Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Xuanwo/backon
Make retry like a built-in feature provided by Rust.
https://github.com/Xuanwo/backon
async backoff retry rust
Last synced: about 1 month ago
JSON representation
Make retry like a built-in feature provided by Rust.
- Host: GitHub
- URL: https://github.com/Xuanwo/backon
- Owner: Xuanwo
- License: apache-2.0
- Created: 2022-04-12T11:48:23.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-28T18:30:37.000Z (about 1 month ago)
- Last Synced: 2024-11-04T18:02:17.433Z (about 1 month ago)
- Topics: async, backoff, retry, rust
- Language: Rust
- Homepage: https://docs.rs/backon/
- Size: 229 KB
- Stars: 711
- Watchers: 5
- Forks: 28
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- my-awesome - Xuanwo/backon - 11 star:0.7k fork:0.0k Make retry like a built-in feature provided by Rust. (Rust)
README
# BackON [![Build Status]][actions] [![Latest Version]][crates.io] [![](https://img.shields.io/discord/1111711408875393035?logo=discord&label=discord)](https://discord.gg/8ARnvtJePD)
[Build Status]: https://img.shields.io/github/actions/workflow/status/Xuanwo/backon/ci.yml?branch=main
[actions]: https://github.com/Xuanwo/backon/actions?query=branch%3Amain
[Latest Version]: https://img.shields.io/crates/v/backon.svg
[crates.io]: https://crates.io/crates/backonMake **retry** like a built-in feature provided by Rust.
- **Simple**: Just like a built-in feature: `your_fn.retry(ExponentialBuilder::default()).await`.
- **Flexible**: Supports both blocking and async functions.
- **Powerful**: Allows control over retry behavior such as [`when`](https://docs.rs/backon/latest/backon/struct.Retry.html#method.when) and [`notify`](https://docs.rs/backon/latest/backon/struct.Retry.html#method.notify).
- **Customizable**: Supports custom retry strategies like [exponential](https://docs.rs/backon/latest/backon/struct.ExponentialBuilder.html), [constant](https://docs.rs/backon/latest/backon/struct.ConstantBuilder.html), etc.
- **Adaptable**: Works on all platforms supported by Rust, including both `wasm` and `no-std`.---
## Quick Start
### Retry an async function.
```rust
use anyhow::Result;
use backon::ExponentialBuilder;
use backon::Retryable;async fn fetch() -> Result {
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.
```rust
use anyhow::Result;
use backon::BlockingRetryable;
use backon::ExponentialBuilder;fn fetch() -> Result {
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](./CONTRIBUTING.md) guide for more details on getting started with contributing to this
project.## Getting help
Submit [issues](https://github.com/Xuanwo/backon/issues/new/choose) for bug report or asking questions
in [discussion](https://github.com/Xuanwo/backon/discussions/new?category=q-a).## License
Licensed under Apache License, Version 2.0.