#futures #tokio #retry #exponential #backoff

tokio-retry

Extensible, asynchronous retry behaviours for futures/tokio

9 releases

0.3.0 Mar 6, 2021
0.2.0 Apr 7, 2018
0.1.1 Oct 27, 2017
0.1.0 Apr 17, 2017
0.0.5 Mar 11, 2017

#110 in Asynchronous

Download history 129036/week @ 2023-10-24 145056/week @ 2023-10-31 134550/week @ 2023-11-07 139268/week @ 2023-11-14 124708/week @ 2023-11-21 145961/week @ 2023-11-28 138403/week @ 2023-12-05 130348/week @ 2023-12-12 111348/week @ 2023-12-19 59989/week @ 2023-12-26 116850/week @ 2024-01-02 129472/week @ 2024-01-09 145912/week @ 2024-01-16 148075/week @ 2024-01-23 137692/week @ 2024-01-30 114945/week @ 2024-02-06

567,925 downloads per month
Used in 230 crates (54 directly)

MIT license

20KB
413 lines

tokio-retry

Extensible, asynchronous retry behaviours for the ecosystem of tokio libraries.

Build Status crates dependency status

Documentation

Installation

Add this to your Cargo.toml:

[dependencies]
tokio-retry = "0.3"

Examples

use tokio_retry::Retry;
use tokio_retry::strategy::{ExponentialBackoff, jitter};

async fn action() -> Result<u64, ()> {
    // do some real-world stuff here...
    Err(())
}

#[tokio::main]
async fn main() -> Result<(), ()> {
    let retry_strategy = ExponentialBackoff::from_millis(10)
        .map(jitter) // add jitter to delays
        .take(3);    // limit to 3 retries

    let result = Retry::spawn(retry_strategy, action).await?;

    Ok(())
}

Dependencies

~2.6–4MB
~69K SLoC