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
Download history 179899/week @ 2024-06-20 190159/week @ 2024-06-27 162811/week @ 2024-07-04 169647/week @ 2024-07-11 172737/week @ 2024-07-18 176712/week @ 2024-07-25 171427/week @ 2024-08-01 190243/week @ 2024-08-08 185488/week @ 2024-08-15 191438/week @ 2024-08-22 186774/week @ 2024-08-29 194234/week @ 2024-09-05 186533/week @ 2024-09-12 174204/week @ 2024-09-19 187492/week @ 2024-09-26 149315/week @ 2024-10-03

730,950 downloads per month
Used in 258 crates (62 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.6–9.5MB
~70K SLoC