1 use std::future::Future;
3 #[tracing::instrument(skip_all)]
4 pub async fn retry<F, Fut, T>(f: F) -> Result<T, reqwest_middleware::Error>
7 Fut: Future<Output = Result<T, reqwest_middleware::Error>>,
9 retry_custom(|| async { Ok((f)().await) }).await
12 #[tracing::instrument(skip_all)]
13 async fn retry_custom<F, Fut, T>(f: F) -> Result<T, reqwest_middleware::Error>
16 Fut: Future<Output = Result<Result<T, reqwest_middleware::Error>, reqwest_middleware::Error>>,
18 let mut response: Option<Result<T, reqwest_middleware::Error>> = None;
22 Ok(t) => return Ok(t),
23 Err(reqwest_middleware::Error::Reqwest(e)) => {
25 response = Some(Err(reqwest_middleware::Error::Reqwest(e)));
28 return Err(reqwest_middleware::Error::Reqwest(e));
31 return Err(otherwise);
36 response.expect("retry http request")