1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
//! This library provides extensible asynchronous retry behaviours //! for use with the popular [`futures`](https://crates.io/crates/futures) crate //! and the ecosystem of [`tokio`](https://tokio.rs/) libraries. //! //! # Installation //! //! Add this to your `Cargo.toml`: //! //! ```toml //! [dependencies] //! tokio-retry = "*" //! ``` //! //! By default, `tokio-retry` will work both with the [`Handle`](https://docs.rs/tokio-core/0.1.4/tokio_core/reactor/struct.Handle.html) type from //! `tokio-core`, and the [`Timer`](https://docs.rs/tokio-timer/0.1.0/tokio_timer/struct.Timer.html) type from `tokio-timer`. //! Both of these can be disabled or enabled via cargo feature flags: //! //! ```toml //! [dependencies.tokio-retry] //! version = "*" //! default-features = false //! # enable only tokio-core compatibility //! features = ["tokio_core"] //! ``` //! //! # Examples //! //! ```rust //! extern crate futures; //! extern crate tokio_timer; //! extern crate tokio_retry; //! //! use std::time::Duration; //! use std::default::Default; //! use futures::future::Future; //! use tokio_timer::Timer; //! use tokio_retry::RetryStrategy; //! use tokio_retry::strategies::ExponentialBackoff; //! //! fn action() -> Result<u64, ()> { //! // do some real-world stuff here... //! Ok(42) //! } //! //! pub fn main() { //! let retry_strategy = ExponentialBackoff::from_millis(10) //! .limit_delay(Duration::from_millis(1000)) //! .limit_retries(3) //! .jitter(); //! let retry_future = retry_strategy.run(Timer::default(), action); //! let retry_result = retry_future.wait(); //! //! assert_eq!(retry_result, Ok(42)); //! } //! ``` extern crate either; extern crate futures; extern crate rand; #[cfg(feature = "tokio_core")] extern crate tokio_core; #[cfg(feature = "tokio_timer")] extern crate tokio_timer; mod future; mod strategy; /// Assorted retry strategies including fixed interval and exponential back-off. pub mod strategies; pub use future::{Sleep, RetryError, RetryFuture}; pub use strategy::*;