forked from TrueCloudLab/frostfs-api-go
3a91383f24
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>
29 lines
617 B
Go
29 lines
617 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// CallOption is a messaging session option within Protobuf RPC.
|
|
type CallOption func(*callParameters)
|
|
|
|
type callParameters struct {
|
|
ctx context.Context
|
|
}
|
|
|
|
func defaultCallParameters() *callParameters {
|
|
return &callParameters{
|
|
ctx: context.Background(),
|
|
}
|
|
}
|
|
|
|
// 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.ctx = ctx
|
|
}
|
|
}
|