#exponential-backoff #future #tokio #exponential #retry #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

#70 in Asynchronous

Download history 171243/week @ 2024-07-27 176916/week @ 2024-08-03 195842/week @ 2024-08-10 181702/week @ 2024-08-17 200803/week @ 2024-08-24 187064/week @ 2024-08-31 190682/week @ 2024-09-07 172733/week @ 2024-09-14 179677/week @ 2024-09-21 190485/week @ 2024-09-28 185200/week @ 2024-10-05 192350/week @ 2024-10-12 209684/week @ 2024-10-19 343163/week @ 2024-10-26 334714/week @ 2024-11-02 300145/week @ 2024-11-09

1,221,731 downloads per month
Used in 254 crates (66 directly)

MIT license

20KB
413 lines

tokio-retry

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

Build Status 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.5–8.5MB
~69K SLoC