Skip to main content

exp_backoff_cap

Function exp_backoff_cap 

Source
pub fn exp_backoff_cap(
    initial: Duration,
    max: Duration,
    multiplier: u32,
    attempt: u32,
) -> Duration
Expand description

Compute the exponential-backoff cap for a given attempt count (0-based: attempt 0 uses initial, attempt 1 uses initial * multiplier, etc.), clamped to max.

Pure, const-friendly, and branch-free on overflow: a runaway attempt count saturates at max_backoff rather than wrapping. Split out as a free function so tests can exercise the full sequence without spinning up a subscriber.