func Continue(c Controller) bool
Continue is a convenience function to check when we can fire the next invocation of the desired backoff code
for backoff.Continue(c) { ... your code ... }
CommonOption is an option that can be passed to any of the backoff policies.
type CommonOption interface { ExponentialOption ConstantOption }
func WithJitterFactor(v float64) CommonOption
WithJitterFactor enables some randomness (jittering) in the computation of the backoff intervals. This value must be between 0.0 < v < 1.0. If a value outside of this range is specified, the value will be silently ignored and jittering is disabled.
This option can be passed to ExponentialPolicy or ConstantPolicy constructor
func WithRNG(v Random) CommonOption
WithRNG specifies the random number generator used for jittering. If not provided one will be created, but if you want a truly random jittering, make sure to provide one that you explicitly initialized
type ConstantInterval struct {
// contains filtered or unexported fields
}
func NewConstantInterval(options ...ConstantOption) *ConstantInterval
func (g *ConstantInterval) Next() time.Duration
ConstantOption is an option that is used by the Constant policy.
type ConstantOption interface { Option // contains filtered or unexported methods }
func WithInterval(v time.Duration) ConstantOption
WithInterval specifies the constant interval used in ConstantPolicy and ConstantInterval. The default value is 1 minute.
type ConstantPolicy struct {
// contains filtered or unexported fields
}
func NewConstantPolicy(options ...Option) *ConstantPolicy
func (p *ConstantPolicy) Start(ctx context.Context) Controller
type Controller interface { Done() <-chan struct{} Next() <-chan struct{} }
ControllerOption is an option that may be passed to Policy objects, but are ultimately passed down to the Controller objects. (Normally you do not have to care about the distinction)
type ControllerOption interface { ConstantOption ExponentialOption CommonOption // contains filtered or unexported methods }
func WithMaxRetries(v int) ControllerOption
WithMaxRetries specifies the maximum number of attempts that can be made by the backoff policies. By default each policy tries up to 10 times.
If you would like to retry forever, specify "0" and pass to the constructor of each policy.
This option can be passed to all policy constructors except for NullPolicy
type ExponentialInterval struct {
// contains filtered or unexported fields
}
func NewExponentialInterval(options ...ExponentialOption) *ExponentialInterval
func (g *ExponentialInterval) Next() time.Duration
ExponentialOption is an option that is used by the Exponential policy.
type ExponentialOption interface { Option // contains filtered or unexported methods }
func WithMaxInterval(v time.Duration) ExponentialOption
WithMaxInterval specifies the maximum duration used in exponential backoff The default value is 1 minute.
func WithMinInterval(v time.Duration) ExponentialOption
WithMinInterval specifies the minimum duration used in exponential backoff. The default value is 500ms.
func WithMultiplier(v float64) ExponentialOption
WithMultiplier specifies the factor in which the backoff intervals are increased. By default this value is set to 1.5, which means that for every iteration a 50% increase in the interval for every iteration (up to the value specified by WithMaxInterval). this value must be greater than 1.0. If the value is less than equal to 1.0, the default value of 1.5 is used.
type ExponentialPolicy struct {
// contains filtered or unexported fields
}
func NewExponentialPolicy(options ...ExponentialOption) *ExponentialPolicy
func (p *ExponentialPolicy) Start(ctx context.Context) Controller
type IntervalGenerator interface { Next() time.Duration }
NullPolicy does not do any backoff. It allows the caller to execute the desired code once, and no more
type NullPolicy struct{}
func NewNull() *NullPolicy
func (p *NullPolicy) Start(ctx context.Context) Controller
type Option = option.Interface
Policy is an interface for the backoff policies that this package implements. Users must create a controller object from this policy to actually do anything with it
type Policy interface { Start(context.Context) Controller }
func Constant(options ...Option) Policy
Constant creates a new ConstantPolicy object
▹ Example
func Exponential(options ...ExponentialOption) Policy
Constant creates a new ExponentialPolicy object
▹ Example
func Null() Policy
Null creates a new NullPolicy object
type Random interface { Float64() float64 }