Skip to main content

exponential_backoff

Function exponential_backoff 

Source
pub fn exponential_backoff(
    attempt: u32,
    base: Duration,
    max: Duration,
) -> Duration
Expand description

Exponential backoff: base * 2^attempt, clamped to max. A pure helper a RetryPolicy can feed to its own async timer; the runtime never sleeps on it.

attempt is 0-based, so attempt 0 waits base, attempt 1 waits 2 * base, and so on. Overflow (a large attempt or base) saturates to max rather than panicking, so every nonzero base reaches max once base * 2^attempt does.