feat: use WithBlock() by default, NonBlock can be set in config or WithNonBlock() (#1198)

This commit is contained in:
Kevin Wan
2021-11-02 19:02:02 +08:00
committed by GitHub
parent b76c7ae55d
commit 1ece3a498f
4 changed files with 25 additions and 1 deletions

View File

@@ -14,6 +14,8 @@ import (
var (
// WithDialOption is an alias of internal.WithDialOption.
WithDialOption = internal.WithDialOption
// WithNonBlock sets the dialing to be nonblock.
WithNonBlock = internal.WithNonBlock
// WithTimeout is an alias of internal.WithTimeout.
WithTimeout = internal.WithTimeout
// WithRetry is an alias of internal.WithRetry.
@@ -57,6 +59,9 @@ func NewClient(c RpcClientConf, options ...ClientOption) (Client, error) {
Token: c.Token,
})))
}
if c.NonBlock {
opts = append(opts, WithNonBlock())
}
if c.Timeout > 0 {
opts = append(opts, WithTimeout(time.Duration(c.Timeout)*time.Millisecond))
}