mirror of
https://github.com/hanzoai/psrpc.git
synced 2026-09-30 23:47:22 +00:00
timeout unanswered requests quickly (#76)
This commit is contained in:
@@ -32,6 +32,7 @@ type ClientOption func(*ClientOpts)
|
|||||||
type ClientOpts struct {
|
type ClientOpts struct {
|
||||||
ClientID string
|
ClientID string
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
|
SelectionTimeout time.Duration
|
||||||
ChannelSize int
|
ChannelSize int
|
||||||
EnableStreams bool
|
EnableStreams bool
|
||||||
RequestHooks []ClientRequestHook
|
RequestHooks []ClientRequestHook
|
||||||
@@ -53,6 +54,12 @@ func WithClientTimeout(timeout time.Duration) ClientOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithClientSelectTimeout(timeout time.Duration) ClientOption {
|
||||||
|
return func(o *ClientOpts) {
|
||||||
|
o.SelectionTimeout = timeout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func WithClientChannelSize(size int) ClientOption {
|
func WithClientChannelSize(size int) ClientOption {
|
||||||
return func(o *ClientOpts) {
|
return func(o *ClientOpts) {
|
||||||
o.ChannelSize = size
|
o.ChannelSize = size
|
||||||
|
|||||||
@@ -30,8 +30,9 @@ func withStreams() psrpc.ClientOption {
|
|||||||
|
|
||||||
func getClientOpts(opts ...psrpc.ClientOption) psrpc.ClientOpts {
|
func getClientOpts(opts ...psrpc.ClientOption) psrpc.ClientOpts {
|
||||||
o := &psrpc.ClientOpts{
|
o := &psrpc.ClientOpts{
|
||||||
Timeout: psrpc.DefaultClientTimeout,
|
Timeout: psrpc.DefaultClientTimeout,
|
||||||
ChannelSize: bus.DefaultChannelSize,
|
SelectionTimeout: psrpc.DefaultAffinityTimeout,
|
||||||
|
ChannelSize: bus.DefaultChannelSize,
|
||||||
}
|
}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(o)
|
opt(o)
|
||||||
@@ -45,11 +46,12 @@ func getRequestOpts(i *info.RequestInfo, options psrpc.ClientOpts, opts ...psrpc
|
|||||||
}
|
}
|
||||||
if i.AffinityEnabled {
|
if i.AffinityEnabled {
|
||||||
o.SelectionOpts = psrpc.SelectionOpts{
|
o.SelectionOpts = psrpc.SelectionOpts{
|
||||||
AffinityTimeout: psrpc.DefaultAffinityTimeout,
|
AffinityTimeout: options.SelectionTimeout,
|
||||||
ShortCircuitTimeout: psrpc.DefaultAffinityShortCircuit,
|
ShortCircuitTimeout: psrpc.DefaultAffinityShortCircuit,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
o.SelectionOpts = psrpc.SelectionOpts{
|
o.SelectionOpts = psrpc.SelectionOpts{
|
||||||
|
AffinityTimeout: options.SelectionTimeout,
|
||||||
AcceptFirstAvailable: true,
|
AcceptFirstAvailable: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user