Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Jitter ¶
Jitter should return a new wait duration optionally with some time added or removed to create some randomness in wait time.
type Waiter ¶
type Waiter struct { // MinFailures before exponential backoff starts. Any failures before // MinFailures is reached will wait MinWait time. MinFailures uint // MinWait time. Returned after the first failure. MinWait time.Duration // MaxWait time applied before Jitter. Note that the actual maximum wait time // is MaxWait + MaxWait * Jitter. MaxWait time.Duration // Jitter to add to each wait time. The Jitter is applied after MaxWait, which // may cause the actual wait time to exceed MaxWait. Jitter Jitter // Factor is the multiplier to use when calculating the delay. Defaults to // 1 second. Factor time.Duration // contains filtered or unexported fields }
Waiter records the number of failures and performs exponential backoff when there are consecutive failures.
func (*Waiter) NextWait ¶ added in v1.14.0
NextWait returns the period the next call to Wait with block for assuming it's context is not cancelled. It's useful for informing a user how long it will be before the next attempt is made.
func (*Waiter) Reset ¶
func (w *Waiter) Reset()
Reset the failure count to 0. Reset must be called if the operation done after Wait did not fail.
func (*Waiter) RetryLoop ¶ added in v1.14.0
RetryLoop retries an operation until either operation completes without error or Waiter's context is canceled.
func (*Waiter) Wait ¶
Wait increases the number of failures by one, and then blocks until the context is cancelled, or until the wait time is reached.
The wait time increases exponentially as the number of failures increases. Every call to Wait increments the failures count, so Reset must be called after Wait when there wasn't a failure.
The only non-nil error that Wait returns will come from ctx.Err(), such as when the context is canceled. This makes it suitable for long-running routines that do not get re-initialized, such as replication.