9 releases (4 breaking)
0.4.1 | May 19, 2023 |
---|---|
0.4.0 | Feb 8, 2023 |
0.3.1 | Feb 8, 2023 |
0.2.0 | Sep 17, 2022 |
0.0.2 | Apr 14, 2022 |
#143 in Science
69,267 downloads per month
Used in 11 crates
(4 directly)
44KB
850 lines
backon

Retry with backoff without effort.
The opposite backoff implementation of the popular backoff.
- Newer: developed by Rust edition 2021 and latest stable.
- Cleaner: Iterator based abstraction, easy to use, customization friendly.
- Easier: Trait based implementations, works like a native function provided by closures.
Quick Start
Retry a blocking function.
use anyhow::Result;
use backon::BlockingRetryable;
use backon::ExponentialBuilder;
fn fetch() -> Result<String> {
Ok("hello, world!".to_string())
}
fn main() -> Result<()> {
let content = fetch.retry(&ExponentialBuilder::default()).call()?;
println!("fetch succeeded: {}", content);
Ok(())
}
Retry an async function.
use anyhow::Result;
use backon::ExponentialBuilder;
use backon::Retryable;
async fn fetch() -> Result<String> {
Ok(reqwest::get("https://www.rust-lang.org").await?.text().await?)
}
#[tokio::main]
async fn main() -> Result<()> {
let content = fetch.retry(&ExponentialBuilder::default()).await?;
println!("fetch succeeded: {}", content);
Ok(())
}
Contributing
Check out the CONTRIBUTING.md guide for more details on getting started with contributing to this project.
Getting help
Submit issues for bug report or asking questions in discussion.
License
Licensed under Apache License, Version 2.0.Dependencies
~2.4–7.5MB
~115K SLoC