Documentation
¶
Index ¶
- Constants
- type Backoff
- func NewConstant(t time.Duration) Backoff
- func NewExponential(base time.Duration) Backoff
- func NewFibonacci(base time.Duration) Backoff
- func NewNoop() Backoff
- func WithCappedDuration(cap time.Duration, next Backoff) Backoff
- func WithJitter(j time.Duration, next Backoff) Backoff
- func WithJitterPercent(j uint64, next Backoff) Backoff
- func WithMaxDuration(timeout time.Duration, next Backoff) Backoff
- func WithMaxRetries(max uint32, next Backoff) Backoff
- type BackoffFunc
- type Retry
Constants ¶
const DefaultConstant = time.Second
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
type Backoff interface { // Next returns the time duration to wait and whether to stop. Next() (next time.Duration, stop bool) }
Backoff is an interface that backs off.
func NewConstant ¶
NewConstant creates a new constant backoff using the value t.
func NewExponential ¶
NewExponential creates a new exponential backoff using the starting value of base and doubling on each failure (1, 2, 4, 8, 16, 32, 64...), up to max. It's very efficient, but does not check for overflow, so ensure you bound the retry.
func NewFibonacci ¶
NewFibonacci creates a new Fibonacci backoff using the starting value of base. The wait time is the sum of the previous two wait times on each failed attempt (1, 1, 2, 3, 5, 8, 13...).
func WithCappedDuration ¶
WithCappedDuration sets a maximum on the duration returned from the next backoff. This is NOT a total backoff time, but rather a cap on the maximum value a backoff can return. Without another middleware, the backoff will continue infinitely.
func WithJitter ¶
WithJitter wraps a backoff function and adds the specified jitter. j can be interpreted as "+/- j". For example, if j were 5 seconds and the backoff returned 20s, the value could be between 15 and 25 seconds. The value can never be less than 0.
func WithJitterPercent ¶
WithJitterPercent wraps a backoff function and adds the specified jitter percentage. j can be interpreted as "+/- j%". For example, if j were 5 and the backoff returned 20s, the value could be between 19 and 21 seconds. The value can never be less than 0 or greater than 100.
func WithMaxDuration ¶
WithMaxDuration sets a maximum on the total amount of time a backoff should execute. It's best-effort, and should not be used to guarantee an exact amount of time.
func WithMaxRetries ¶
WithMaxRetries executes the backoff function up until the maximum attempts.
type BackoffFunc ¶
BackoffFunc is a backoff expressed as a function.