Documentation ¶
Index ¶
Constants ¶
const Stop time.Duration = -1
Stop indicates that no more retries should be made.
Variables ¶
This section is empty.
Functions ¶
func Fatal ¶
Fatal tags an error as fatal. If the callback passed to Retry() returns a fatal error, Retry() will quit retrying and exit early (returning the error passed to Fatal) even there are remaining attempts.
func Retry ¶
Retry the operation using the provided back-off policy until it succeeds, or the context is cancelled. Any intermediate errors (but not the final error) returned by the function will be sent on the given channel, if the channel is non-nil.
If f returns an error wrapped with Fatal(), Retry() will stop retrying the operation and exit, returning the wrapped error.
Types ¶
type Backoff ¶
type Backoff interface { // Next gets the duration to wait before retrying the operation or |Stop| // to indicate that no retries should be made. Next() time.Duration // Reset resets to initial state. Reset() }
func NoRetries ¶
func NoRetries() Backoff
NoRetries returns a backoff that will do a single attempt, with no retries.
func WithMaxAttempts ¶
WithMaxAttempts wraps a back-off which stops after |max| attempts. If the max is 0, then it won't apply a maximum number attempts.
type ConstantBackoff ¶
type ConstantBackoff struct {
// contains filtered or unexported fields
}
ConstantBackoff is a fixed policy that always returns the same backoff delay.
func NewConstantBackoff ¶
func NewConstantBackoff(d time.Duration) *ConstantBackoff
func (*ConstantBackoff) Next ¶
func (b *ConstantBackoff) Next() time.Duration
func (*ConstantBackoff) Reset ¶
func (b *ConstantBackoff) Reset()
type ExponentialBackoff ¶
type ExponentialBackoff struct {
// contains filtered or unexported fields
}
ExponentialBackoff is a policy that increase the delay exponentially, with a small amount of randomness.
func NewExponentialBackoff ¶
func NewExponentialBackoff(initialInterval time.Duration, maxInterval time.Duration, multiplier float64) *ExponentialBackoff
NewExponentialBackoff returns a new ExponentialBackoff object. If maxInterval is non-positive, no maximum is imposed.
func (*ExponentialBackoff) Next ¶
func (e *ExponentialBackoff) Next() time.Duration
func (*ExponentialBackoff) Reset ¶
func (e *ExponentialBackoff) Reset()
type ZeroBackoff ¶
type ZeroBackoff struct{}
ZeroBackoff is a fixed policy whose back-off time is always zero, meaning that the operation is retried immediately without waiting.
func (*ZeroBackoff) Next ¶
func (b *ZeroBackoff) Next() time.Duration
func (*ZeroBackoff) Reset ¶
func (b *ZeroBackoff) Reset()