Module retry

Source
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.
RetryReader
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.
RetryState
The state of a retry operation constructed with Retry.
RetryStream
Opaque type representing the stream of retries that continues to back off.

Enums§

RetryReaderState 🔒
RetryReaderStateProj 🔒
RetryResult
The result of a retryable operation.