Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (c *Client) SendRequest(requestBody Params, responseBody Response) error {

var response *opcodes.RequestResponse

timer := time.NewTimer(c.ResponseTimeout * time.Millisecond)
timer := time.NewTimer(c.ResponseTimeout)
defer timer.Stop()
select {
case response = <-c.IncomingResponses:
Expand Down
22 changes: 19 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,24 @@ func WithRequestHeader(x http.Header) Option {
// WithResponseTimeout sets the time we're willing to wait to receive a response
// from the server for any request, before responding with an error. It's in
// milliseconds. The default timeout is 10 seconds.
//
// Deprecated: WithResponseTimeout interprets its argument as milliseconds, even
// though it is typed as [time.Duration]. Prefer WithResponseTimeoutDuration,
// which takes a proper [time.Duration] value.
func WithResponseTimeout(x time.Duration) Option {
return func(o *Client) { o.client.ResponseTimeout = time.Duration(x) }
return WithResponseTimeoutDuration(x * time.Millisecond)
}

// WithResponseTimeoutDuration sets the time we're willing to wait to receive a
// response from the server for any request, before responding with an error.
func WithResponseTimeoutDuration(x time.Duration) Option {
if x <= 0 {
x = 10 * time.Second
}

return func(o *Client) {
o.client.ResponseTimeout = x
}
}

// WithScheme sets the protocol scheme to use when connecting to the server,
Expand Down Expand Up @@ -165,7 +181,7 @@ func New(host string, opts ...Option) (*Client, error) {
Disconnected: make(chan struct{}),
IncomingResponses: make(chan *opcodes.RequestResponse),
Opcodes: make(chan opcodes.Opcode),
ResponseTimeout: 10000,
ResponseTimeout: 10 * time.Second,
Log: log.New(
&logutils.LevelFilter{
Levels: []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "ERROR", ""},
Expand Down Expand Up @@ -233,7 +249,7 @@ func (c *Client) connect() (err error) {
close(c.client.IncomingResponses)
}()

timer := time.NewTimer(c.client.ResponseTimeout * time.Millisecond)
timer := time.NewTimer(c.client.ResponseTimeout)
defer timer.Stop()
select {
case a := <-authComplete:
Expand Down
Loading