You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sync & Async: Supports both blocking and async operations seamlessly.
Precise Control: Define when to retry and get notified via when and notify.
Custom Strategies: Use built-in backoff strategies (exponential, constant) or define custom ones. Also supports dynamic backoff, such as using the HTTP Retry-After header.
Cross-Platform: Works everywhere Rust does, including wasm & no-std.
use anyhow::Result;use backon::ExponentialBuilder;use backon::Retryable;asyncfnfetch() -> Result<String>{Ok("hello, world!".to_string())}#[tokio::main]asyncfnmain() -> Result<()>{let content = fetch
// Retry with exponential backoff.retry(ExponentialBuilder::default())// Sleep implementation, required if no feature has been enabled.sleep(tokio::time::sleep)// When to retry.when(|e| e.to_string() == "EOF")// Notify when retrying.notify(|err:&anyhow::Error,dur:Duration| {println!("retrying {:?} after {:?}", err, dur);}).await?;println!("fetch succeeded: {}", content);Ok(())}
Retry a blocking function.
use anyhow::Result;use backon::BlockingRetryable;use backon::ExponentialBuilder;fnfetch() -> Result<String>{Ok("hello, world!".to_string())}fnmain() -> Result<()>{let content = fetch
// Retry with exponential backoff.retry(ExponentialBuilder::default())// Sleep implementation, required if no feature has been enabled.sleep(std::thread::sleep)// When to retry.when(|e| e.to_string() == "EOF")// Notify when retrying.notify(|err:&anyhow::Error,dur:Duration| {println!("retrying {:?} after {:?}", err, dur);}).call()?;println!("fetch succeeded: {}", content);Ok(())}
Contributing
Check out the CONTRIBUTING.md guide for more details on getting started with contributing to this
project.