tokio-retry

Crates.iotokio-retry
lib.rstokio-retry
version0.3.0
sourcesrc
created_at2017-03-05 13:07:28.724889
updated_at2021-03-06 13:07:27.598743
descriptionExtensible, asynchronous retry behaviours for futures/tokio
homepage
repositoryhttps://github.com/srijs/rust-tokio-retry
max_upload_size
id8827
size23,264
Sam Rijs (srijs)

documentation

https://docs.rs/tokio-retry

README

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(())
}
Commit count: 76

cargo fmt