3 releases

0.1.2 May 31, 2020
0.1.1 May 30, 2020
0.1.0 May 12, 2020

#1422 in Asynchronous

Download history 18556/week @ 2025-09-18 22451/week @ 2025-09-25 22863/week @ 2025-10-02 21033/week @ 2025-10-09 19014/week @ 2025-10-16 22760/week @ 2025-10-23 18986/week @ 2025-10-30 19222/week @ 2025-11-06 21430/week @ 2025-11-13 26668/week @ 2025-11-20 23442/week @ 2025-11-27 24287/week @ 2025-12-04 23640/week @ 2025-12-11 13824/week @ 2025-12-18 5110/week @ 2025-12-25 15376/week @ 2026-01-01

63,319 downloads per month
Used in 14 crates (6 directly)

MIT license

19KB
329 lines

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

again = "0.1"

🤸usage

For very simple cases you can use the module level retry function to retry a potentially fallible operation.

use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    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.

use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    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.

use std::error::Error;
use std::time::Duration;
use again::RetryPolicy;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    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 for more examples.

Doug Tangren (softprops) 2020

Dependencies

~2.2–4.5MB
~81K SLoC