Crate tokio_retry
source · [−]Expand description
This library provides extensible asynchronous retry behaviours
for use with the popular futures
crate
and the ecosystem of tokio
libraries.
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));
}
Re-exports
pub use middleware::Middleware;
Modules
Middleware for tokio services that adds automatic retries in case of failure.
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.
Enums
Represents the errors possible during the execution of the RetryFuture
.