Documentation ¶
Index ¶
Constants ¶
const Stop time.Duration = -1
Stop is a sentinel value returned by a Iterator to indicate that no more attempts should be made.
Variables ¶
This section is empty.
Functions ¶
func Retry ¶
Retry executes a function 'fn'. If the function returns an error, it will be re-executed according to a retry plan.
If a Factory is supplied, it will be called to generate a single retry Iterator for this Retry round. If nil, Retry will execute the target function exactly once regardless of return value.
If the supplied context is canceled, retry will stop executing. Retry will not execute the supplied function at all if the context is canceled when Retry is invoked.
If 'callback' is not nil, it will be invoked if an error occurs (prior to sleeping).
Types ¶
type Callback ¶
Callback is a callback function that Retry will invoke every time an attempt fails prior to sleeping.
type ExponentialBackoff ¶
type ExponentialBackoff struct { Limited // Multiplier is the exponential growth multiplier. If < 1, a default of 2 // will be used. Multiplier float64 // MaxDelay is the maximum duration. If <= zero, no maximum will be enforced. MaxDelay time.Duration }
ExponentialBackoff is an Iterator implementation that implements exponential backoff retry.
type Factory ¶
type Factory func() Iterator
Factory is a function that produces an independent Iterator instance.
Since each Iterator is mutated as it is iterated through, this is used to produce a fresh Iterator for a new round of retries. Unless the caller is fully aware of what they're doing, this should not return the an Iterator instance more than once.
type Iterator ¶
type Iterator interface { // Returns the next retry delay, or Stop if no more retries should be made. Next(context.Context, error) time.Duration }
Iterator describes a stateful implementation of retry logic.
func Default ¶
func Default() Iterator
Default is a Factory that returns a new instance of the default iterator configuration.
func NewIterator ¶
NewIterator creates an Iterator based on a "next" function. It is a concise way to implement an Iterator.
type Limited ¶
type Limited struct { // Delay is the next generated delay. Delay time.Duration // Retries, if >= 0, is the number of remaining retries. If <0, no retry // count will be applied. Retries int // MaxTotal is the maximum total elapsed time. If <= 0, no maximum will be // enforced. MaxTotal time.Duration // contains filtered or unexported fields }
Limited is an Iterator implementation that may be limited by a maximum number of retries and/or time.