First crack at backoff function

This commit is contained in:
Asim
2016-04-05 20:04:37 +01:00
parent 56c6993eb8
commit 7167f998ce
5 changed files with 86 additions and 0 deletions

View File

@@ -37,6 +37,8 @@ type Options struct {
type CallOptions struct {
SelectOptions []selector.SelectOption
// Backoff func
Backoff BackoffFunc
// Transport Dial Timeout
DialTimeout time.Duration
// Number of Call attempts
@@ -67,6 +69,7 @@ func newOptions(options ...Option) Options {
opts := Options{
Codecs: make(map[string]codec.NewCodec),
CallOptions: CallOptions{
Backoff: DefaultBackoff,
Retries: DefaultRetries,
RequestTimeout: DefaultRequestTimeout,
DialTimeout: transport.DefaultDialTimeout,
@@ -151,6 +154,14 @@ func Wrap(w Wrapper) Option {
}
}
// Backoff is used to set the backoff function used
// when retrying Calls
func Backoff(fn BackoffFunc) Option {
return func(o *Options) {
o.CallOptions.Backoff = fn
}
}
// Number of retries when making the request.
// Should this be a Call Option?
func Retries(i int) Option {
@@ -182,6 +193,14 @@ func WithSelectOption(so selector.SelectOption) CallOption {
}
}
// WithBackoff is a CallOption which overrides that which
// set in Options.CallOptions
func WithBackoff(fn BackoffFunc) CallOption {
return func(o *CallOptions) {
o.Backoff = fn
}
}
// WithRetries is a CallOption which overrides that which
// set in Options.CallOptions
func WithRetries(i int) CallOption {