type ExponentialBackOff … type Clock … type ExponentialBackOffOpts … const DefaultInitialInterval … const DefaultRandomizationFactor … const DefaultMultiplier … const DefaultMaxInterval … const DefaultMaxElapsedTime … // NewExponentialBackOff creates an instance of ExponentialBackOff using default values. func NewExponentialBackOff(opts ...ExponentialBackOffOpts) *ExponentialBackOff { … } // WithInitialInterval sets the initial interval between retries. func WithInitialInterval(duration time.Duration) ExponentialBackOffOpts { … } // WithRandomizationFactor sets the randomization factor to add jitter to intervals. func WithRandomizationFactor(randomizationFactor float64) ExponentialBackOffOpts { … } // WithMultiplier sets the multiplier for increasing the interval after each retry. func WithMultiplier(multiplier float64) ExponentialBackOffOpts { … } // WithMaxInterval sets the maximum interval between retries. func WithMaxInterval(duration time.Duration) ExponentialBackOffOpts { … } // WithMaxElapsedTime sets the maximum total time for retries. func WithMaxElapsedTime(duration time.Duration) ExponentialBackOffOpts { … } // WithRetryStopDuration sets the duration after which retries should stop. func WithRetryStopDuration(duration time.Duration) ExponentialBackOffOpts { … } // WithClockProvider sets the clock used to measure time. func WithClockProvider(clock Clock) ExponentialBackOffOpts { … } type systemClock … func (t systemClock) Now() time.Time { … } var SystemClock … // Reset the interval back to the initial retry interval and restarts the timer. // Reset must be called before using b. func (b *ExponentialBackOff) Reset() { … } // NextBackOff calculates the next backoff interval using the formula: // Randomized interval = RetryInterval * (1 ± RandomizationFactor) func (b *ExponentialBackOff) NextBackOff() time.Duration { … } // GetElapsedTime returns the elapsed time since an ExponentialBackOff instance // is created and is reset when Reset() is called. // // The elapsed time is computed using time.Now().UnixNano(). It is // safe to call even while the backoff policy is used by a running // ticker. func (b *ExponentialBackOff) GetElapsedTime() time.Duration { … } // Increments the current interval by multiplying it with the multiplier. func (b *ExponentialBackOff) incrementCurrentInterval() { … } // Returns a random value from the following interval: // [currentInterval - randomizationFactor * currentInterval, currentInterval + randomizationFactor * currentInterval]. func getRandomValueFromInterval(randomizationFactor, random float64, currentInterval time.Duration) time.Duration { … }