pub async fn retry<F, Fut, T>(
op_name: impl Into<String>,
strategy: impl BackoffBuilder,
op_fn: F,
) -> Result<T, Error>
Expand description
Run the supplied closure op_fn
until it succeeds. Frequency and number of
retries is determined by the specified strategy.
use std::time::Duration;
use fedimint_core::util::{backon, retry};
retry(
"Gateway balance after swap".to_string(),
backon::FibonacciBuilder::default()
.with_min_delay(Duration::from_millis(200))
.with_max_delay(Duration::from_secs(3))
.with_max_times(10),
|| async {
// Fallible network calls …
Ok(())
},
)
.await
.expect("never fails");
§Returns
- If the closure runs successfully, the result is immediately returned
- If the closure did not run successfully for
max_attempts
times, the error of the closure is returned