Help us shape the future of Go! Take the 2026 Go Developer Survey

backoff

package
v1.104.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: BSD-3-Clause Imports: 5 Imported by: 1

Documentation

Overview

Package backoff provides a back-off timer type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff struct {

	// tstime.Clock.NewTimer is used instead time.NewTimer.
	Clock tstime.Clock

	// LogLongerThan sets the minimum time of a single backoff interval
	// before we mention it in the log.
	LogLongerThan time.Duration
	// contains filtered or unexported fields
}

Backoff tracks state the history of consecutive failures and sleeps an increasing amount of time, up to a provided limit.

func NewBackoff

func NewBackoff(name string, logf logger.Logf, maxBackoff time.Duration) *Backoff

NewBackoff returns a new Backoff timer with the provided name (for logging), logger, and max backoff time. By default, all failures (calls to BackOff with a non-nil err) are logged unless the returned Backoff.LogLongerThan is adjusted.

func (*Backoff) BackOff

func (b *Backoff) BackOff(ctx context.Context, err error)

BackOff sleeps an increasing amount of time if err is non-nil while the context is active. It resets the backoff schedule once err is nil.

func (*Backoff) Reset added in v1.92.0

func (b *Backoff) Reset()

Reset resets the backoff schedule, equivalent to calling BackOff with a nil error.

Jump to

Keyboard shortcuts

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