Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMaxRetry = errors.New("exceeded maximum number of retries")
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
type Backoff struct {
// contains filtered or unexported fields
}
Backoff is used to do capped exponential backoff with jitter, with a maximum number of retries. Generally, use this struct by calling Next() or NextSleep() after a failure. If configured for N max retries, Next() and NextSleep() will return an error on the call N+1. The jitter is set to 25%, so values returned will have up to 25% less than twice the previous value. The min value will also include jitter, so the first call will almost always be less than the requested minimum value. Backoff is not thread-safe.
func NewBackoff ¶
NewBackoff creates a new exponential backoff with the given number of maximum retries and min/max durations.
func (*Backoff) Current ¶
Current returns the next time that will be returned by Next() (or slept in NextSleep()).
func (*Backoff) Next ¶
Next determines the next backoff duration that is roughly twice the current value, capped to a max value, with a measure of randomness. It returns an error if there are no more retries left.
func (*Backoff) NextSleep ¶
NextSleep will synchronously sleep the next backoff amount (see Next()). It returns an error if there are no more retries left.