use std::future::Future; #[tracing::instrument(skip_all)] pub async fn retry(f: F) -> Result where F: Fn() -> Fut, Fut: Future>, { retry_custom(|| async { Ok((f)().await) }).await } #[tracing::instrument(skip_all)] #[allow(clippy::expect_used)] async fn retry_custom(f: F) -> Result where F: Fn() -> Fut, Fut: Future, reqwest_middleware::Error>>, { let mut response: Option> = None; for _ in 0u8..3 { match (f)().await? { Ok(t) => return Ok(t), Err(reqwest_middleware::Error::Reqwest(e)) => { if e.is_timeout() { response = Some(Err(reqwest_middleware::Error::Reqwest(e))); continue; } return Err(reqwest_middleware::Error::Reqwest(e)); } Err(otherwise) => { return Err(otherwise); } } } response.expect("retry http request") }