项目
在 GitHub 查看 BackON

Xuanwo/backon
Xuanwo/backon has 1,067 GitHub stars and 59 forks. GitHot measured +1 stars in 24 hours and +1 in 7 days. Last checked 2026-11-11 01:18 UTC. Last push 2026-11-02.
Make retry like a built-in feature provided by Rust.
实测星标增长
- 24小时
- +1
- 7天
- +1
- 15天
- 更新延迟
- 1个月
- 更新延迟
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文BackON


Make retry like a built-in feature provided by Rust.
- Simple API: Native feel:
your_fn.retry(ExponentialBuilder::default()).await. - Sync & Async: Supports both blocking and async operations seamlessly.
- Precise Control: Define when to retry and get notified via
whenandnotify. - Custom Strategies: Use built-in backoff strategies (exponential, constant) or define custom ones. Also supports dynamic backoff, such as using the HTTP
Retry-Afterheader. - Cross-Platform: Works everywhere Rust does, including
wasm&no-std.
Quick Start
For more examples, check out the examples.
Retry an async function.
use anyhow::Result;
use backon::ExponentialBuilder;
use backon::Retryable;
async fn fetch() -> Result<String> {
Ok("hello, world!".to_string())
}
#[tokio::main]
async fn main() -> 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;
fn fetch() -> Result<String> {
Ok("hello, world!".to_string())
}
fn main() -> 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.
Getting help
Submit issues for bug report or asking questions in discussion.
License
Licensed under Apache License, Version 2.0.