Skip to content

Extensible, asynchronous retry behaviours for futures/tokio

License

Notifications You must be signed in to change notification settings

df5602/rust-tokio-retry

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tokio-retry

Extensible, asynchronous retry behaviours based on futures, for the ecosystem of tokio libraries.

crates

Documentation

Installation

Add this to your Cargo.toml:

[dependencies]
tokio-retry = "0.1"

Examples

extern crate tokio_core;
extern crate tokio_retry;

use tokio_core::reactor::Core;
use tokio_retry::Retry;
use tokio_retry::strategy::{ExponentialBackoff, jitter};

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

fn main() {
    let mut core = Core::new().unwrap();

    let retry_strategy = ExponentialBackoff::from_millis(10)
        .map(jitter)
        .take(3);
  
    let retry_future = Retry::spawn(core.handle(), retry_strategy, action);
    let retry_result = core.run(retry_future);

    assert_eq!(retry_result, Ok(42));
}

About

Extensible, asynchronous retry behaviours for futures/tokio

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%