3 releases

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

#208 in WebAssembly

Download history 10373/week @ 2023-11-27 9938/week @ 2023-12-04 9639/week @ 2023-12-11 11092/week @ 2023-12-18 5114/week @ 2023-12-25 8300/week @ 2024-01-01 10332/week @ 2024-01-08 12547/week @ 2024-01-15 13894/week @ 2024-01-22 11317/week @ 2024-01-29 9482/week @ 2024-02-05 12233/week @ 2024-02-12 12624/week @ 2024-02-19 12416/week @ 2024-02-26 11799/week @ 2024-03-04 5452/week @ 2024-03-11

42,865 downloads per month
Used in 17 crates (7 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

~1.7–4MB
~74K SLoC