async_repeat 0.1.0

Retry futures mechanism
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use async_retry::{AsyncRetry, LinearRetryStrategy, RetryPolicy};
use std::time::Duration;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let text = AsyncRetry::new(
        || async { Ok::<_, RetryPolicy>(reqwest::get("http://localhost:8084").await?.text().await?) },
        LinearRetryStrategy::default()
            .max_attempts(10)
            .delay_between_repeats(Duration::from_millis(100)),
    )
    .await?;

    eprintln!("text = {:#?}", text);

    Ok(())
}