add stream timeout option which defaults to 0 (#1456)

* add stream timeout option which defaults to 0

* fix option
This commit is contained in:
Asim Aslam 2020-03-31 23:22:11 +01:00 committed by GitHub
parent 1490aff38e
commit 68b0238a5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -221,7 +221,9 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client
} }
// set timeout in nanoseconds // set timeout in nanoseconds
header["timeout"] = fmt.Sprintf("%d", opts.RequestTimeout) if opts.StreamTimeout > time.Duration(0) {
header["timeout"] = fmt.Sprintf("%d", opts.StreamTimeout)
}
// set the content type for the request // set the content type for the request
header["x-content-type"] = req.ContentType() header["x-content-type"] = req.ContentType()

View File

@ -57,6 +57,8 @@ type CallOptions struct {
Retries int Retries int
// Request/Response timeout // Request/Response timeout
RequestTimeout time.Duration RequestTimeout time.Duration
// Stream timeout for the stream
StreamTimeout time.Duration
// Use the services own auth token // Use the services own auth token
ServiceToken bool ServiceToken bool
@ -227,6 +229,13 @@ func RequestTimeout(d time.Duration) Option {
} }
} }
// StreamTimeout sets the stream timeout
func StreamTimeout(d time.Duration) Option {
return func(o *Options) {
o.CallOptions.StreamTimeout = d
}
}
// Transport dial timeout // Transport dial timeout
func DialTimeout(d time.Duration) Option { func DialTimeout(d time.Duration) Option {
return func(o *Options) { return func(o *Options) {
@ -295,6 +304,13 @@ func WithRequestTimeout(d time.Duration) CallOption {
} }
} }
// WithStreamTimeout sets the stream timeout
func WithStreamTimeout(d time.Duration) CallOption {
return func(o *CallOptions) {
o.StreamTimeout = d
}
}
// WithDialTimeout is a CallOption which overrides that which // WithDialTimeout is a CallOption which overrides that which
// set in Options.CallOptions // set in Options.CallOptions
func WithDialTimeout(d time.Duration) CallOption { func WithDialTimeout(d time.Duration) CallOption {

View File

@ -198,7 +198,9 @@ func (r *rpcClient) stream(ctx context.Context, node *registry.Node, req Request
} }
// set timeout in nanoseconds // set timeout in nanoseconds
msg.Header["Timeout"] = fmt.Sprintf("%d", opts.RequestTimeout) if opts.StreamTimeout > time.Duration(0) {
msg.Header["Timeout"] = fmt.Sprintf("%d", opts.StreamTimeout)
}
// set the content type for the request // set the content type for the request
msg.Header["Content-Type"] = req.ContentType() msg.Header["Content-Type"] = req.ContentType()
// set the accept header // set the accept header