exponential_backoff

package
v1.17.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 3 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	MaxExponentialBackoffDelay         = 32 * time.Second
	ExponentialDelayFactor     float64 = 2.0  // Each delta delay is twice bigger.
	ExponentialDelayRandomMs           = 1000 // Each delay has random additional milliseconds.
)

Variables

View Source
var ExponentialCalculationsCount = int(math.Log(MaxExponentialBackoffDelay.Seconds()) / math.Log(ExponentialDelayFactor))

ExponentialCalculationsCount counts of exponential calculations before return max delay to prevent overflow with big numbers.

Functions

func CalculateDelay

func CalculateDelay(initialDelay time.Duration, retryCount int) time.Duration

CalculateDelay returns delay distributed from initialDelay to default maxDelay (32s)

Example:

Retry 0: 5s
Retry 1: 6s
Retry 2: 7.8s
Retry 3: 9.8s
Retry 4: 13s
Retry 5: 21s
Retry 6: 32s
Retry 7: 32s

func CalculateDelayWithMax

func CalculateDelayWithMax(initialDelay time.Duration, maxDelay time.Duration, retryCount int) time.Duration

CalculateDelayWithMax returns delay distributed from initialDelay to maxDelay based on retryCount number.

Delay for retry number 0 is an initialDelay.

Calculation of exponential delays starts from retry number 1.

After ExponentialCalculationsCount rounds of calculations, maxDelay is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL