backoff

package
v0.0.0-...-b4a68df Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package backoff provides a simple implementation of exponential backoff.

Index

Constants

View Source
const (
	DefaultMinInterval = 100 * time.Millisecond
	DefaultMaxInterval = 60 * time.Second
	DefaultMultiplier  = 1.5
)

Default values for Backoff.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff struct {
	// MinInterval is the initial interval for the backoff. It is used to set the
	// lower bound on the range of intervals returned from [Backoff.Next].
	MinInterval time.Duration
	// MaxInterval is the maximum interval that should be returned from
	// [Backoff.Next].
	MaxInterval time.Duration
	// Multiplier is the Multiplier used when computing the next interval.
	Multiplier float64
	// Jitter is used to specify a range of randomness for intervals.
	Jitter time.Duration
	// contains filtered or unexported fields
}

Backoff is a simple exponential backoff implementation. The zero Backoff is valid and will use default configuration values. It is not thread-safe.

func (*Backoff) Next

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

Next returns the next interval to wait.

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset returns the interval back to the initial state.

type Ticker

type Ticker struct {
	DisableInstantTick bool
	// contains filtered or unexported fields
}

A Ticker is like time.Ticker but accepts a Backoff.

func NewTicker

func NewTicker(b Backoff) *Ticker

NewTicker constructs a new Ticker with the provided Backoff.

func (*Ticker) Next

func (t *Ticker) Next() <-chan time.Time

Next returns a receive-only channel that produces at intervals determined by the configured Backoff.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop stops the ticker by closing the underlying ticker channel. It is safe to call multiple times.

Jump to

Keyboard shortcuts

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