| Crates.io | tokio-retry |
| lib.rs | tokio-retry |
| version | 0.3.0 |
| created_at | 2017-03-05 13:07:28.724889+00 |
| updated_at | 2021-03-06 13:07:27.598743+00 |
| description | Extensible, asynchronous retry behaviours for futures/tokio |
| homepage | |
| repository | https://github.com/srijs/rust-tokio-retry |
| max_upload_size | |
| id | 8827 |
| size | 23,264 |
Extensible, asynchronous retry behaviours for the ecosystem of tokio libraries.
Add this to your Cargo.toml:
[dependencies]
tokio-retry = "0.3"
use tokio_retry::Retry;
use tokio_retry::strategy::{ExponentialBackoff, jitter};
async fn action() -> Result<u64, ()> {
// do some real-world stuff here...
Err(())
}
#[tokio::main]
async fn main() -> Result<(), ()> {
let retry_strategy = ExponentialBackoff::from_millis(10)
.map(jitter) // add jitter to delays
.take(3); // limit to 3 retries
let result = Retry::spawn(retry_strategy, action).await?;
Ok(())
}