Skip to main content

Crate tool_retry_policy

Crate tool_retry_policy 

Source
Expand description

§tool-retry-policy

Declarative retry policy primitive. Returns “how long to wait, then retry” or “give up”. You run the call; this crate decides whether to retry and for how long.

  • Exponential backoff: base * 2^(attempt-1), capped at max.
  • Optional uniform jitter (default ±25%) using a tiny PRNG.
  • Per-attempt cap (max_attempts).

§Example

use tool_retry_policy::{Policy, Decision};
use std::time::Duration;

let p = Policy {
    max_attempts: 4,
    base: Duration::from_millis(100),
    max: Duration::from_secs(10),
    jitter: false,
};

let mut attempt = 0;
loop {
    attempt += 1;
    // run the call here; pretend it failed
    match p.next(attempt) {
        Decision::Retry(d) => { /* sleep d, continue */ break }
        Decision::GiveUp => break,
    }
}

Structs§

Policy
Retry policy.

Enums§

Decision
Decision returned by next.