mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-13 18:00:00 +08:00
feat(zrpc): change NonBlock default to true following gRPC best practices (#5259)
This commit is contained in:
@@ -141,6 +141,15 @@ func (c *client) dial(server string, opts ...ClientOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithBlock sets the dialing to be blocking.
|
||||
// Deprecated: blocking dials are not recommended by gRPC.
|
||||
// See https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md
|
||||
func WithBlock() ClientOption {
|
||||
return func(options *ClientOptions) {
|
||||
options.NonBlock = false
|
||||
}
|
||||
}
|
||||
|
||||
// WithDialOption returns a func to customize a ClientOptions with given dial option.
|
||||
func WithDialOption(opt grpc.DialOption) ClientOption {
|
||||
return func(options *ClientOptions) {
|
||||
|
||||
@@ -34,6 +34,13 @@ func TestWithNonBlock(t *testing.T) {
|
||||
assert.True(t, options.NonBlock)
|
||||
}
|
||||
|
||||
func TestWithBlock(t *testing.T) {
|
||||
var options ClientOptions
|
||||
opt := WithBlock()
|
||||
opt(&options)
|
||||
assert.False(t, options.NonBlock)
|
||||
}
|
||||
|
||||
func TestWithStreamClientInterceptor(t *testing.T) {
|
||||
var options ClientOptions
|
||||
opt := WithStreamClientInterceptor(func(ctx context.Context, desc *grpc.StreamDesc,
|
||||
|
||||
Reference in New Issue
Block a user