Documentation
¶
Index ¶
Constants ¶
const MaxAttemptsBeforeResetDefault = 7
MaxAttemptsBeforeResetDefault is the number of attempts during exponential backoff after which attempts is reset so that sleep durations aren't flung into a ridiculously distant future. This constant is typically injected into the CancellableSleepExponentialBackoff function. It could technically take another value instead, but shouldn't unless there's a good reason to do so.
The value of 7 corresponds to a max sleep duration of 64 seconds ±10% jitter.
Variables ¶
This section is empty.
Functions ¶
func CancellableSleep ¶
CancellableSleep sleeps for the given duration, but returns early if context has been cancelled.
func CancellableSleepC ¶
CancellableSleepC sleeps for the given duration, but returns early if context has been cancelled.
This variant returns a channel that should be waited on and which will be closed when either the sleep or context is done.
func ExponentialBackoff ¶
ExponentialBackoff returns a duration for a reasonable exponential backoff interval for a service based on the given attempt number, which can then be fed into CancellableSleep to perform the sleep. Uses a 2**N second algorithm, +/- 10% random jitter. Sleep is cancelled if the given context is cancelled.
Attempt should start at one for the first backoff/failure.
Backoff values when using MaxAttemptsBeforeResetDefault are: - 1s - 2s - 4s - 8s - 16s - 32s - 64s.
Types ¶
This section is empty.