Documentation ¶
Index ¶
- Constants
- type DelayDecider
- func Constant(d time.Duration) DelayDecider
- func Exponential(initial time.Duration, multiplier float64) DelayDecider
- func Never() DelayDecider
- func StopAfterMaxAttempts(decider DelayDecider, maxAttempts uint) DelayDecider
- func StopAfterMaxDelay(decider DelayDecider, maxDelay time.Duration) DelayDecider
- func StopAfterMaxTime(decider DelayDecider, maxTime time.Duration) DelayDecider
- func WithJitter(decider DelayDecider, jitter time.Duration) DelayDecider
- func WithJitterFactor(decider DelayDecider, jitterScale float64) DelayDecider
- func WithMaxDelay(decider DelayDecider, maxDelay time.Duration) DelayDecider
Constants ¶
const Stop time.Duration = -1
Stop indicates that no more retries should be made.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DelayDecider ¶
DelayDecider returns the duration to wait before the next retry based on the current attempt and when the action being retried started.
- attempt is the current attempt, starting at 1. - startTime is the time when the first attempt was made.
May return Stop to indicate that no more retries should be made.
func Constant ¶
func Constant(d time.Duration) DelayDecider
Constant returns a delay decider that always returns the same delay.
func Exponential ¶
func Exponential(initial time.Duration, multiplier float64) DelayDecider
Exponential returns a delay decider that returns an exponential delay. The delay is calculated as initial * multiplier^(attempt-1).
Example:
decider := Exponential(1*time.Second, 2) decider(1, ...) // 1s decider(2, ...) // 2s decider(3, ...) // 4s
func StopAfterMaxAttempts ¶
func StopAfterMaxAttempts(decider DelayDecider, maxAttempts uint) DelayDecider
StopAfterMaxAttempts creates a DelayDecider that stops the retrying after a certain number of attempts.
Example:
decider := StopAfterMaxAttempts(Exponential(1*time.Second, 2), 3) decider(1, ...) // 1s decider(2, ...) // 2s decider(3, ...) // 4s decider(4, ...) // backoff.Stop
func StopAfterMaxDelay ¶
func StopAfterMaxDelay(decider DelayDecider, maxDelay time.Duration) DelayDecider
StopAfterMaxDelay creates a DelayDecider that stops the retrying after a certain delay has been reached.
Example:
decider := StopAfterMaxDelay(Exponential(1*time.Second, 2), 5*time.Second) decider(1) // 1s decider(2) // 2s decider(3) // 4s decider(4) // backoff.Stop
func StopAfterMaxTime ¶
func StopAfterMaxTime(decider DelayDecider, maxTime time.Duration) DelayDecider
StopAfterMaxTime creates a DelayDecider that stops the retrying after a certain amount of time has passed.
Example:
decider := StopAfterMaxTime(Exponential(1*time.Second, 2), 5*time.Second) startTime := time.Now() decider(1, startTime) // 1s time.Sleep(5 * time.Second) decider(2, startTime) // backoff.Stop
func WithJitter ¶
func WithJitter(decider DelayDecider, jitter time.Duration) DelayDecider
WithJitter add a jitter to the delay returned by another delay decider. The jitter will be a random value between -jitter and +jitter.
Example:
WithJitter(Exponential(1*time.Second, 2), 100*time.Millisecond)
func WithJitterFactor ¶
func WithJitterFactor(decider DelayDecider, jitterScale float64) DelayDecider
Example:
WithJitterFactor(Exponential(1*time.Second, 2), 0.1)
func WithMaxDelay ¶
func WithMaxDelay(decider DelayDecider, maxDelay time.Duration) DelayDecider
WithMaxDelay applies a maximum delay to an existing delay decider. This will not limit the number of attempts, only the delay between attempts.
Example:
decider := WithMaxDelay(Exponential(1*time.Second, 2), 5*time.Second) decider(1, ...) // 1s decider(2, ...) // 2s decider(3, ...) // 4s decider(4, ...) // 5s (instead of 8s)