backoff

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package backoff provides exponential back-off with jitter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff struct {
	// Base is the initial delay returned on the first call to Next.
	Base time.Duration
	// Multiplier is applied on each successive attempt (e.g. 2.0 doubles).
	Multiplier float64
	// MaxDelay caps the delay before jitter is applied.
	MaxDelay time.Duration
	// Jitter is the fraction of the delay applied as a symmetric random offset,
	// e.g. 0.2 means ±20%.
	Jitter float64
	// contains filtered or unexported fields
}

Backoff computes exponential back-off delays with optional jitter. The zero value is not useful; use a struct literal with explicit fields.

b := &backoff.Backoff{
    Base:       time.Second,
    Multiplier: 2,
    MaxDelay:   60 * time.Second,
    Jitter:     0.2,
}

func (*Backoff) Next

func (b *Backoff) Next() time.Duration

Next returns the next back-off duration and advances the internal counter. The sequence is: Base, Base*Multiplier, Base*Multiplier², … capped at MaxDelay. A random jitter of ±Jitter*delay is added to spread concurrent retries.

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset resets the attempt counter so the next call to Next returns the base delay.

Jump to

Keyboard shortcuts

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