backoff

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package backoff provides exponential backoff with full jitter for retry logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// InitialInterval is the base sleep duration before the first retry.
	InitialInterval time.Duration

	// MaxInterval is the upper bound on the computed sleep duration.
	MaxInterval time.Duration

	// Multiplier is applied to the interval on each successive attempt.
	// A value of 2.0 doubles the interval each time.
	Multiplier float64

	// RandomFactor is the fraction of the interval added as jitter.
	// 0.0 = no jitter, 1.0 = up to ±100% jitter (full jitter).
	RandomFactor float64
}

Config holds parameters for exponential backoff with optional jitter.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a backoff configuration suitable for most use cases. 100ms initial, 30s max, 2x multiplier, 50% jitter.

func (Config) Next

func (c Config) Next(attempt int) time.Duration

Next returns the sleep duration for the given attempt number (0-indexed). It computes: min(MaxInterval, InitialInterval * Multiplier^attempt) * (1 ± RandomFactor).

Jump to

Keyboard shortcuts

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