Available on crate feature
async
only.Expand description
Retry utilities.
This module provides an API for retrying fallible asynchronous operations until they succeed or until some criteria for giving up has been reached, using exponential backoff between retries.
§Examples
Retry a contrived fallible operation until it succeeds:
use std::time::Duration;
use mz_ore::retry::Retry;
let res = Retry::default().retry(|state| {
if state.i == 3 {
Ok(())
} else {
Err("contrived failure")
}
});
assert_eq!(res, Ok(()));
Limit the number of retries such that success is never observed:
use std::time::Duration;
use mz_ore::retry::Retry;
let res = Retry::default().max_tries(2).retry(|state| {
if state.i == 3 {
Ok(())
} else {
Err("contrived failure")
}
});
assert_eq!(res, Err("contrived failure"));
Structs§
- Retry
- Configures a retry operation.
- Retry
Reader - Wrapper of a
Reader
factory that will automatically retry and resume reading an underlying resource in the events of errors according to a retry schedule. - Retry
State - The state of a retry operation constructed with
Retry
. - Retry
Stream - Opaque type representing the stream of retries that continues to back off.
Enums§
- Retry
Reader 🔒State - Retry
Reader 🔒State Proj - Retry
Result - The result of a retryable operation.