Crates.io | backon |
lib.rs | backon |
version | 0.4.4 |
source | src |
created_at | 2022-04-12 09:46:07.418989 |
updated_at | 2024-04-08 03:40:22.445434 |
description | Retry with backoff without effort. |
homepage | |
repository | https://github.com/Xuanwo/backon |
max_upload_size | |
id | 566344 |
size | 113,563 |
Retry with backoff without effort.
The opposite backoff implementation of the popular backoff.
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(())
}
Check out the CONTRIBUTING.md guide for more details on getting started with contributing to this project.
Submit issues for bug report or asking questions in discussion.