Crate tokio_retry [−] [src]
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.2"
Examples
Using the new tokio
crate
use tokio_retry::Retry; use tokio_retry::strategy::{ExponentialBackoff, jitter}; fn action() -> Result<u64, ()> { // do some real-world stuff here... Err(()) } 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
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(()) } 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();
Modules
strategy |
Assorted retry strategies including fixed interval and exponential back-off. |
Structs
Retry |
Future that drives multiple attempts at an action via a retry strategy. |
RetryIf |
Future that drives multiple attempts at an action via a retry strategy. Retries are only attempted if
the |
Enums
Error |
Represents the errors possible during the execution of the |
Traits
Action |
An action can be run multiple times and produces a future. |
Condition |
Specifies under which conditions a retry is attempted. |