retry

package
v1.3.6 Latest Latest
Warning

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

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

Documentation

Overview

Package retry provides a small exponential backoff helper used by reconnect / retry loops across the codebase (gRPC stream reconnect, Docker engine reconnect, runtime probe retry).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff struct {
	// Min is the base interval used for attempt 0. Must be > 0.
	Min time.Duration
	// Max is the upper bound on the (un-jittered) delay.
	Max time.Duration
	// Jitter spreads the delay by ±Jitter (e.g. 0.25 means ±25%).
	// 0 disables jitter and produces deterministic doubling.
	Jitter float64
	// contains filtered or unexported fields
}

Backoff implements exponential backoff with optional jitter. It is NOT safe for concurrent use by multiple goroutines.

func New

func New(min, max time.Duration, jitter float64) *Backoff

New creates a Backoff. Pass jitter = 0 to disable randomization.

func (*Backoff) Attempt

func (b *Backoff) Attempt() int

Attempt returns the current attempt count (0 before the first Next call).

func (*Backoff) Next

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

Next returns the next backoff delay and advances the attempt counter. The base delay doubles on each call up to Max, then jitter is applied.

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset clears the attempt counter so the next Next() call returns Min again.

func (*Backoff) Sleep

func (b *Backoff) Sleep(ctx context.Context) error

Sleep waits for the next backoff delay or until ctx is cancelled. Returns ctx.Err() on cancellation, nil if the delay elapsed normally.

Jump to

Keyboard shortcuts

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