forked from TrueCloudLab/frostfs-sdk-go
[#331] client: Allow to set timeout for streaming operations
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
71891029da
commit
43a57d42dd
1 changed files with 19 additions and 0 deletions
|
@ -80,9 +80,18 @@ func (c *Client) Dial(prm PrmDial) error {
|
|||
prm.timeoutDial = 5 * time.Second
|
||||
}
|
||||
|
||||
if prm.streamTimeoutSet {
|
||||
if prm.streamTimeout <= 0 {
|
||||
panic("non-positive timeout")
|
||||
}
|
||||
} else {
|
||||
prm.streamTimeout = 10 * time.Second
|
||||
}
|
||||
|
||||
c.c = *client.New(append(
|
||||
client.WithNetworkURIAddress(prm.endpoint, prm.tlsConfig),
|
||||
client.WithDialTimeout(prm.timeoutDial),
|
||||
client.WithRWTimeout(prm.streamTimeout),
|
||||
)...)
|
||||
|
||||
// TODO: (neofs-api-go#382) perform generic dial stage of the client.Client
|
||||
|
@ -149,6 +158,9 @@ type PrmDial struct {
|
|||
|
||||
timeoutDialSet bool
|
||||
timeoutDial time.Duration
|
||||
|
||||
streamTimeoutSet bool
|
||||
streamTimeout time.Duration
|
||||
}
|
||||
|
||||
// SetServerURI sets server URI in the NeoFS network.
|
||||
|
@ -182,3 +194,10 @@ func (x *PrmDial) SetTimeout(timeout time.Duration) {
|
|||
x.timeoutDialSet = true
|
||||
x.timeoutDial = timeout
|
||||
}
|
||||
|
||||
// SetStreamTimeout sets the timeout for individual operations in streaming RPC.
|
||||
// MUST BE positive. If not called, 10s timeout will be used by default.
|
||||
func (x *PrmDial) SetStreamTimeout(timeout time.Duration) {
|
||||
x.streamTimeoutSet = true
|
||||
x.streamTimeout = timeout
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue