forked from TrueCloudLab/frostfs-api-go
[#419] rpc/client: Use provided context for client dial
In previous implementation `Client` passed `context.Background()` to `grpc.DialContext` function. This didn't allow to abort dial stage by the given context. Base dial context on the one provided with `WithContext` option. Fall back to using `context.Background` if context is not specified. Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
This commit is contained in:
parent
2b89b7e798
commit
3a91383f24
3 changed files with 19 additions and 13 deletions
|
@ -2,26 +2,28 @@ package client
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/rpc/grpc"
|
||||
)
|
||||
|
||||
// CallOption is a messaging session option within Protobuf RPC.
|
||||
type CallOption func(*callParameters)
|
||||
|
||||
type callParameters struct {
|
||||
callOpts []grpc.CallOption
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func defaultCallParameters() *callParameters {
|
||||
return &callParameters{
|
||||
callOpts: make([]grpc.CallOption, 0, 1),
|
||||
ctx: context.Background(),
|
||||
}
|
||||
}
|
||||
|
||||
// WithContext return options to specify call context.
|
||||
// WithContext returns option to specify call context. If provided, all network
|
||||
// communications will be based on this context. Otherwise, context.Background()
|
||||
// is used.
|
||||
//
|
||||
// Context SHOULD NOT be nil.
|
||||
func WithContext(ctx context.Context) CallOption {
|
||||
return func(prm *callParameters) {
|
||||
prm.callOpts = append(prm.callOpts, grpc.WithContext(ctx))
|
||||
prm.ctx = ctx
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue