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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! 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 = "0.2"
//! ```
//!
//! # Examples
//!
//! ## Using the new `tokio` crate
//!
//! ```rust
//! # extern crate futures;
//! # extern crate tokio;
//! # extern crate tokio_retry;
//! #
//! # use futures::Future;
//! # use futures::future::lazy;
//! use tokio_retry::Retry;
//! use tokio_retry::strategy::{ExponentialBackoff, jitter};
//!
//! fn action() -> Result<u64, ()> {
//!     // do some real-world stuff here...
//!     Err(())
//! }
//!
//! # fn main() {
//! let retry_strategy = ExponentialBackoff::from_millis(10)
//!     .map(jitter)
//!     .take(3);
//!
//! let future = Retry::spawn(retry_strategy, action).then(|result| {
//!     println!("result {:?}", result);
//!     Ok(())
//! });
//!
//! tokio::run(future);
//! # }
//! ```
//!
//! ## Using the `tokio_core` crate
//!
//! ```rust
//! # extern crate futures;
//! # extern crate tokio_core;
//! # extern crate tokio_retry;
//! #
//! # use futures::Future;
//! # use futures::future::lazy;
//! 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...
//!     Err(())
//! }
//!
//! # fn main() {
//! let mut core = Core::new().unwrap();
//!
//! let retry_strategy = ExponentialBackoff::from_millis(10)
//!     .map(jitter)
//!     .take(3);
//!
//! let future = Retry::spawn(retry_strategy, action).then(|result| {
//!     println!("result {:?}", result);
//!     Ok::<_, ()>(())
//! });
//!
//! core.run(future).unwrap();
//! # }
//! ```

extern crate futures;
extern crate rand;
extern crate tokio_timer;

mod action;
mod condition;
mod future;
/// Assorted retry strategies including fixed interval and exponential back-off.
pub mod strategy;

pub use action::Action;
pub use condition::Condition;
pub use future::{Error, Retry, RetryIf};