[#331] client: Allow to set timeout for streaming operations

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-09-06 18:17:54 +03:00 committed by LeL
parent 71891029da
commit 43a57d42dd

View file

@ -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
}