@@ -84,8 +84,24 @@ func WithRequestHeader(x http.Header) Option {
8484// WithResponseTimeout sets the time we're willing to wait to receive a response
8585// from the server for any request, before responding with an error. It's in
8686// milliseconds. The default timeout is 10 seconds.
87+ //
88+ // Deprecated: WithResponseTimeout interprets its argument as milliseconds, even
89+ // though it is typed as [time.Duration]. Prefer WithResponseTimeoutDuration,
90+ // which takes a proper [time.Duration] value.
8791func WithResponseTimeout (x time.Duration ) Option {
88- return func (o * Client ) { o .client .ResponseTimeout = time .Duration (x ) }
92+ return WithResponseTimeoutDuration (x * time .Millisecond )
93+ }
94+
95+ // WithResponseTimeoutDuration sets the time we're willing to wait to receive a
96+ // response from the server for any request, before responding with an error.
97+ func WithResponseTimeoutDuration (x time.Duration ) Option {
98+ if x <= 0 {
99+ x = 10 * time .Second
100+ }
101+
102+ return func (o * Client ) {
103+ o .client .ResponseTimeout = x
104+ }
89105}
90106
91107// WithScheme sets the protocol scheme to use when connecting to the server,
@@ -165,7 +181,7 @@ func New(host string, opts ...Option) (*Client, error) {
165181 Disconnected : make (chan struct {}),
166182 IncomingResponses : make (chan * opcodes.RequestResponse ),
167183 Opcodes : make (chan opcodes.Opcode ),
168- ResponseTimeout : 10000 ,
184+ ResponseTimeout : 10 * time . Second ,
169185 Log : log .New (
170186 & logutils.LevelFilter {
171187 Levels : []logutils.LogLevel {"TRACE" , "DEBUG" , "INFO" , "ERROR" , "" },
@@ -233,7 +249,7 @@ func (c *Client) connect() (err error) {
233249 close (c .client .IncomingResponses )
234250 }()
235251
236- timer := time .NewTimer (c .client .ResponseTimeout * time . Millisecond )
252+ timer := time .NewTimer (c .client .ResponseTimeout )
237253 defer timer .Stop ()
238254 select {
239255 case a := <- authComplete :
0 commit comments