Documentation ¶
Index ¶
- Constants
- func Retry(backoff Backoff, fn func() error) error
- func RetryCtx(ctx context.Context, backoff Backoff, fn func() error) error
- type Backoff
- type ExponentialBackoff
- func (b *ExponentialBackoff) NextBackoff() time.Duration
- func (b *ExponentialBackoff) WithFactor(factor float64) *ExponentialBackoff
- func (b *ExponentialBackoff) WithInitial(initial time.Duration) *ExponentialBackoff
- func (b *ExponentialBackoff) WithMultiplier(multiplier float64) *ExponentialBackoff
- func (b *ExponentialBackoff) WithRandom(random Random) *ExponentialBackoff
- type IntervalBackoff
- type Random
Constants ¶
const ( DefaultExponentialInitial = 100 * time.Millisecond DefaultExponentialFactor = 0.5 DefaultExponentialMultiplier = 1.5 )
Default values for ExponentialBackoff.
const Stop time.Duration = -1
Stop is a special backoff duration that stops the retry immediately.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Backoff ¶
type Backoff interface { // NextBackoff returns the next backoff duration. // If the returned duration <= 0, then Retry stops immediately. NextBackoff() time.Duration }
Backoff is a backoff policy for retrying operations.
func WithMaxInterval ¶
WithMaxInterval returns a backoff policy that makes sure that the backoff duration never exceeds the given maximum.
func WithMaxRetries ¶
WithMaxRetries returns a backoff policy that stops after the given number of retries.
type ExponentialBackoff ¶
type ExponentialBackoff struct {
// contains filtered or unexported fields
}
ExponentialBackoff is a policy that waits exponentially longer between retries.
func NewExponentialBackoff ¶
func NewExponentialBackoff() *ExponentialBackoff
NewExponentialBackoff returns ExponentialBackoff with default settings.
func (*ExponentialBackoff) NextBackoff ¶
func (b *ExponentialBackoff) NextBackoff() time.Duration
func (*ExponentialBackoff) WithFactor ¶
func (b *ExponentialBackoff) WithFactor(factor float64) *ExponentialBackoff
WithFactor sets the factor for randomizing the backoff duration.
func (*ExponentialBackoff) WithInitial ¶
func (b *ExponentialBackoff) WithInitial(initial time.Duration) *ExponentialBackoff
WithInitial sets the initial backoff duration.
func (*ExponentialBackoff) WithMultiplier ¶
func (b *ExponentialBackoff) WithMultiplier(multiplier float64) *ExponentialBackoff
WithMultiplier sets the multiplier for increasing the backoff duration.
func (*ExponentialBackoff) WithRandom ¶
func (b *ExponentialBackoff) WithRandom(random Random) *ExponentialBackoff
WithRandom sets the random number generator.
type IntervalBackoff ¶
type IntervalBackoff struct {
// contains filtered or unexported fields
}
IntervalBackoff is a backoff policy that waits a fixed interval between retries.
func NewIntervalBackoff ¶
func NewIntervalBackoff(interval time.Duration) *IntervalBackoff
NewIntervalBackoff returns IntervalBackoff with the given interval.
func (*IntervalBackoff) NextBackoff ¶
func (b *IntervalBackoff) NextBackoff() time.Duration