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 = "*"
By default, tokio-retry
will work both with the Handle
type from
tokio-core
, and the Timer
type from tokio-timer
.
Both of these can be disabled or enabled via cargo feature flags:
[dependencies.tokio-retry]
version = "*"
default-features = false
# enable only tokio-core compatibility
features = ["tokio_core"]
Examples
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)); }
Modules
decorators |
Decorators adding functionality to retry strategies. |
strategies |
Assorted retry strategies including fixed interval and exponential back-off. |
Structs
RetryFuture |
Future that drives multiple attempts at an action via a retry strategy. |
Enums
RetryError |
Represents the errors possible during the execution of the |
Traits
RetryStrategy |
Trait that specifies a retry behaviour. |
Sleep |