retry

package
v0.0.0-...-b8a15ae Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JitterFull = "full"
	JitterNone = "none"
)

The jitter vocabulary, spelled the way the spec spells it. An empty field means full jitter, which is the default the project chose: retries without spread synchronise into a thundering herd against whatever just stumbled.

Variables

This section is empty.

Functions

func Delay

func Delay(p Policy, attempt int, rnd *rand.Rand) time.Duration

Delay returns how long to wait before the attempt after the one that just failed. Attempt is 1-based and names the attempt that failed; values below one count as the first. Rnd is the injected source of randomness; it must be non-nil unless the policy's jitter is none, and the same seed always replays the same draws.

The function is pure: no clock, no globals, no state. Monotonic in the attempt until the cap, never above MaxDelay, never negative, and free of overflow for any attempt number, because growth stops at the cap instead of doubling past it. Durations this side of 292 years are safe.

Types

type Kind

type Kind string

Kind names the backoff shape a policy grows its delays by.

const (
	// Exponential doubles the initial delay every attempt.
	Exponential Kind = "exponential"
	// Fixed keeps the initial delay flat across attempts.
	Fixed Kind = "fixed"
)

type Policy

type Policy struct {
	Backoff  Kind
	Initial  time.Duration
	MaxDelay time.Duration
	Jitter   string
}

Policy is one step's retry timing, already parsed and validated by internal/spec. It is pure data: everything a delay needs and nothing about who computes it or when.

Jump to

Keyboard shortcuts

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