https://github.com/softprops/again
♻️ Retry faillible Rustlang std library futures
https://github.com/softprops/again
futures retry wasm
Last synced: 6 months ago
JSON representation
♻️ Retry faillible Rustlang std library futures
- Host: GitHub
- URL: https://github.com/softprops/again
- Owner: softprops
- License: mit
- Created: 2020-05-10T05:56:51.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2024-07-29T20:41:02.000Z (about 1 year ago)
- Last Synced: 2025-03-17T11:59:47.190Z (7 months ago)
- Topics: futures, retry, wasm
- Language: Rust
- Homepage:
- Size: 797 KB
- Stars: 58
- Watchers: 2
- Forks: 17
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
again ♻️
wasm-compatible retry interfaces for fallible Rustlang std library Futures
A goal of any operation should be a successful outcome. This crate gives operations a better chance at achieving that.
## 📦 install
In your Cargo.toml file, add the following under the `[dependencies]` heading
```toml
again = "0.1"
```## 🤸usage
For very simple cases you can use the module level `retry` function
to retry a potentially fallible operation.```rust
use std::error::Error;#[tokio::main]
async fn main() -> Result<(), Box> {
pretty_env_logger::init();
again::retry(|| reqwest::get("https://api.you.com")).await?;
Ok(())
}
```You may not want to retry _every_ kind of error. For preciseness you can be more explicit in which kinds of errors should be retried with the module level `retry_if` function.
```rust
use std::error::Error;#[tokio::main]
async fn main() -> Result<(), Box> {
pretty_env_logger::init();
again::retry_if(
|| reqwest::get("https://api.you.com")
reqwest::Error::is_status
).await?;
Ok(())
}
```You can also customize retry behavior to suit your applications needs
with a configurable and reusable `RetryPolicy`.```rust
use std::error::Error;
use std::time::Duration;
use again::RetryPolicy;#[tokio::main]
async fn main() -> Result<(), Box> {
pretty_env_logger::init();
let policy = RetryPolicy::exponential(Duration::from_millis(200))
.with_max_retries(10)
.with_jitter(true);
policy.retry(|| reqwest::get("https://api.you.com")).await?;
Ok(())
}
```See the [docs](http://docs.rs/again) for more examples.
Doug Tangren (softprops) 2020