error-concept

Retry backoff and delay budget

Plan capped exponential delays within a separate waiting budget. Production retries also need operation deadlines, jitter and repeat safety. This example calculates delays rather than sleeping and is not an end-to-end deadline implementation. Expected stdout (not executed): wait 100 ms wait 200 ms remaining 200 ms Expected stderr: (empty) Expected exit: success Common mistake: Treating a delay budget as a guarantee of total request duration.

Formal Syntax & Structure

rust syntaxrust
delay.saturating_mul(2).min(cap)

Working Example

Example Snippetrust
fn main() {    let mut delay = 100_u64;    let mut budget = 500_u64;    for _ in 0..4 {        if delay > budget { break; }        println!("wait {delay} ms");        budget -= delay;        delay = delay.saturating_mul(2).min(300);    }    println!("remaining {budget} ms");}
Rust Reference