retry
Runs operation until it succeeds, at most attempts times, and returns the first success or
the last error.
operation receives the number of the attempt, starting at 1, so it can wait before a retry
(for instance with backoff) or log it: this helper never sleeps, so it
works the same in a test as in production. attempts of 0 is treated as 1: an operation
is always tried once.
Import
Section titled “Import”Cargo feature function (enabled by default). To compile only this module:
or in Cargo.toml:
Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
attempts | u32 | The most times to run operation. |
operation | impl FnMut(u32) -> Result<T, E> | The work to try, given the attempt number. |
Returns
Section titled “Returns”Result<T, E> — Ok on success, otherwise an Err: see Errors.
Errors
Section titled “Errors”The error of the last attempt, when every attempt failed.
