Crate tokio_retry

source ·
Expand description

This library provides extensible asynchronous retry behaviours for use with the ecosystem of tokio libraries.

§Installation

Add this to your Cargo.toml:

[dependencies]
tokio-retry = "0.3"

§Example

use tokio_retry::Retry;
use tokio_retry::strategy::{ExponentialBackoff, jitter};

async fn action() -> Result<u64, ()> {
    // do some real-world stuff here...
    Err(())
}

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?;

Modules§

  • Assorted retry strategies including fixed interval and exponential back-off.

Structs§

  • Future that drives multiple attempts at an action via a retry strategy.
  • Future that drives multiple attempts at an action via a retry strategy. Retries are only attempted if the Error returned by the future satisfies a given condition.

Traits§

  • An action can be run multiple times and produces a future.
  • Specifies under which conditions a retry is attempted.