[][src]Crate again

Again is a wasm-compatible utility for retrying standard library Futures with a Result output type

A goal of any operation should be a successful outcome. This crate gives operations a better chance at achieving that.


Hello world

For simple cases, you can use the module level retry fn, which will retry a task every second for 5 seconds with an exponential backoff.

again::retry(|| reqwest::get("https://api.company.com"));

Conditional retries

By default, again will retry any failed Future if its Result output type is an Err. You may not want to retry every kind of error. In those cases you may wish to use the retry_if fn, which accepts an additional argument to conditionally determine if the error should be retried.

    || reqwest::get("https://api.company.com"),

Retry policies

Every application has different needs. The default retry behavior in again likely will not suit all of them. You can define your own retry behavior with a RetryPolicy. A RetryPolicy can be configured with a fixed or exponential backoff, jitter, and other common retry options. This objects may be reused across operations. For more information see the RetryPolicy docs.

This example is not tested
use again::RetryPolicy;
use std::time::Duration;

let policy = RetryPolicy::fixed(Duration::from_millis(100))

policy.retry(|| reqwest::get("https://api.company.com"));


For visibility on when operations fail and are retried, a log::trace message is emitted, logging the Debug display of the error and the delay before the next attempt.

wasm features

again supports WebAssembly targets i.e. wasm32-unknown-unknown which should make this crate a good fit for most environments

Two cargo features exist to support various wasm runtimes: wasm-bindgen and stdweb. To enable them add the following to your Cargo.toml file.

again = { version = "xxx", features = ["wasm-bindgen"] }



A template for configuring retry behavior



A type to determine if a failed Future should be retried


A unit of work to be retried



Retries a fallible Future with a default RetryPolicy


Retries a fallible Future under a certain provided conditions with a default RetryPolicy