#exponential-backoff #retry #async #future #tokio #behavior

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

#72 in Asynchronous

Download history 480368/week @ 2025-02-11 433892/week @ 2025-02-18 406391/week @ 2025-02-25 800685/week @ 2025-03-04 671095/week @ 2025-03-11 1083777/week @ 2025-03-18 919121/week @ 2025-03-25 564744/week @ 2025-04-01 563498/week @ 2025-04-08 419464/week @ 2025-04-15 416191/week @ 2025-04-22 350722/week @ 2025-04-29 420089/week @ 2025-05-06 411571/week @ 2025-05-13 369381/week @ 2025-05-20 306755/week @ 2025-05-27

1,570,906 downloads per month
Used in 276 crates (76 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.4–8.5MB
~64K SLoC