#exponential-backoff #retry #future #tokio #backoff #exponential

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

#120 in Asynchronous

Download history 368897/week @ 2024-11-17 266338/week @ 2024-11-24 294967/week @ 2024-12-01 411570/week @ 2024-12-08 359135/week @ 2024-12-15 97081/week @ 2024-12-22 169181/week @ 2024-12-29 375353/week @ 2025-01-05 460356/week @ 2025-01-12 372220/week @ 2025-01-19 444314/week @ 2025-01-26 474077/week @ 2025-02-02 506378/week @ 2025-02-09 408168/week @ 2025-02-16 422447/week @ 2025-02-23 719675/week @ 2025-03-02

2,079,047 downloads per month
Used in 259 crates (70 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
~68K SLoC