Documentation
¶
Index ¶
- func CappedExponentialDelay(coef time.Duration, base int, cap time.Duration) func(int) time.Duration
- func CappedLinearDelay(step time.Duration, cap time.Duration) func(int) time.Duration
- func ConstantDelay(delay time.Duration) func(int) time.Duration
- func ExponentialDelay(coef time.Duration, base int) func(int) time.Duration
- func LinearDelay(step time.Duration) func(int) time.Duration
- func NoDelay() func(int) time.Duration
- type Retrier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CappedExponentialDelay ¶
func CappedExponentialDelay( coef time.Duration, base int, cap time.Duration, ) func(int) time.Duration
CappedExponentialDelay returns a delay function that creates an exponentially increasing wait duration between retries up to a specific limit where delay can not be longer.. The delay is calculated by (coef*base^retries).
func CappedLinearDelay ¶
CappedLinearDelay returns a delay function that creates a linearly increasing wait duration between retries up to a specific limit where delay can not be longer. The delay is calculated by min((delay*retries), cap)
func ConstantDelay ¶
ConstantDelay returns a delay function that creates a constant wait duration between retries. The delay will be the same between the retries.
func ExponentialDelay ¶
ExponentialDelay returns a delay function that creates an exponentially increasing wait duration between retries. The delay is calculated by (coef*base^retries).
func LinearDelay ¶
LinearDelay returns a delay function that creates a linearly increasing wait duration between retries. The delay is calculated by (step*retries).
Types ¶
type Retrier ¶
type Retrier struct {
// contains filtered or unexported fields
}
Retrier controls how to to run the retry function. A task will be retried up to a set retry count with some delay between the retries defined by a delay function.
func NewRetrier ¶
NewRetrier creates a retrier from max retries and a delay function.
func (*Retrier) RunCtx ¶
func (r *Retrier) RunCtx( ctx context.Context, work func(ctx context.Context) (error, bool), ) error
RunCtx executes a work task in the context of a retrier until the task decides not to retry, or if the maximum retries have been reached, or if the context has been canceled and retrying should stop.