Documentation
¶
Overview ¶
Package backoff provides an exponential backoff schedule with optional additive jitter and a configurable cap. It is designed to drive reconnect loops (APRS-IS client) and restart supervisors (modembridge child process), which previously each carried their own nearly-identical implementation.
A Backoff is not safe for concurrent use; each caller owns one.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
type Backoff struct {
// contains filtered or unexported fields
}
Backoff is the stateful schedule. The zero value is not usable; call New.
func New ¶
New builds a Backoff from cfg. Panics on an invalid configuration so callers discover the problem at startup rather than after a failure already occurred.
type Config ¶
type Config struct {
// Initial is the first delay returned by Next. Required; a
// non-positive value panics in New.
Initial time.Duration
// Max caps the schedule. Once the growing delay reaches Max it
// stays there. Zero means "unbounded" (capped at math.MaxInt64).
Max time.Duration
// Factor is the growth multiplier applied after each Next call.
// Zero defaults to 2.0 (classic "double each time").
Factor float64
// JitterFrac is the upper bound of additive jitter as a fraction
// of the current delay: the returned value is current +
// Uniform[0, current*JitterFrac). Zero disables jitter entirely.
// Must be in [0, 1); values outside that range panic.
JitterFrac float64
// Rand is the random source used for jitter. Ignored when
// JitterFrac is 0. When nil and JitterFrac > 0, a time-seeded
// source is created in New; tests that want deterministic jitter
// should supply their own source.
Rand *rand.Rand
}
Config describes one Backoff schedule.
Click to show internal directories.
Click to hide internal directories.