Expand description
§Retry Policy
Configurable retry logic with multiple back-off strategies, jitter modes, and async execution support.
§Example
use tokio_prompt_orchestrator::retry_policy::{
JitterMode, RetryPolicy, RetryStrategy, retry_async,
};
let policy = RetryPolicy {
strategy: RetryStrategy::ExponentialBackoff {
initial_ms: 10,
multiplier: 2.0,
max_ms: 1000,
},
jitter: JitterMode::Full,
max_attempts: 3,
retryable_errors: vec![],
};
let call_count = std::sync::atomic::AtomicU32::new(0);
let result: Result<(), String> = retry_async(&policy, || async {
let n = call_count.fetch_add(1, std::sync::atomic::Ordering::SeqCst) + 1;
if n < 3 { Err("transient".to_string()) } else { Ok(()) }
}).await;
assert!(result.is_ok());Structs§
- Retry
Metrics - Summary of a completed retry sequence.
- Retry
Policy - A complete retry configuration.
- Retry
State - Mutable state tracked across retry attempts.
Enums§
- Jitter
Mode - Jitter strategy to reduce correlated retry storms.
- Retry
Strategy - The back-off strategy that determines how long to wait between retry attempts.
Functions§
- retry_
async - Executes
fup topolicy.max_attemptstimes, sleeping between attempts according to the policy, and returns the firstOkresult or the last error.