pub async fn retry<F, Fut, T, E, D>(
f: F,
config: Config<D>,
) -> Result<T, Error<E>>Expand description
Retries a fallible async operation with the given configuration.
The operation f is called repeatedly. On success the value is returned.
On failure the config’s delay strategy determines how long to wait before
retrying. Once the configured number of attempts is exhausted, the last
error is returned wrapped in Error.
If attempts is 0 (the default), the operation is retried forever
until it succeeds.
§Example
use std::time::Duration;
use retry::{retry, Config};
use retry::delay::Fixed;
let result = retry(
|| async { Ok::<_, &'static str>("hello") },
Config::new(Fixed::new(Duration::from_millis(10))).with_attempts(3),
)
.await?;
assert_eq!(result, "hello");