ExponentialBackoff

class ExponentialBackoff(base: Duration, cap: Duration, factor: Double = 2.0, random: Random)

Full-jitter exponential backoff. Stateless: delay is a pure function of the 0-based attempt, so the caller keeps the attempt counter (it resets naturally each retry episode). Randomness is an injected dependency — pass a seeded Random in tests for determinism.

The delay for an attempt is uniform in [0, min(cap, base · factor^attempt)) ("full jitter") — decorrelating many simultaneous retriers so a shared-transport blip that flaps N edges at once does not produce a synchronized reconnect storm.

Constructors

Link copied to clipboard
constructor(base: Duration, cap: Duration, factor: Double = 2.0, random: Random)

Functions

Link copied to clipboard
fun delay(attempt: Int): Duration

Full-jitter delay for attempt (0-based). Never negative; clamped to cap; overflow-safe.