backoff

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0 modules, 0 packages

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

Overview

Package backoff provides exponential backoff with jitter and context-aware sleeping.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sleep

func Sleep(ctx context.Context, d time.Duration) bool

Sleep waits for d and reports false if ctx is cancelled first. If d <= 0, it returns ctx.Err() == nil without waiting.

Types

type Backoff

type Backoff struct {
	// contains filtered or unexported fields
}

Backoff computes exponential reconnect delays with jitter (ADR 0006, ADR 0034). It is not safe for concurrent use by multiple goroutines.

func FullJitter

func FullJitter(minD, maxD time.Duration, randIntN func(int64) int64) *Backoff

FullJitter returns a Backoff whose Wait returns delays in [0, cur) where cur = min(maxD, minD*2^n). If randIntN is nil, math/rand/v2.Int64N is used.

func HalfJitter

func HalfJitter(minD, maxD time.Duration) *Backoff

HalfJitter returns a Backoff whose Wait returns delays in [cur/2, cur) and doubles cur up to maxD on each call.

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset restores the backoff delay to its initial minimum.

func (*Backoff) Wait

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

Wait returns the next jittered delay and advances the backoff state.

Jump to

Keyboard shortcuts

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