Skip to main content

run

Function run 

Source
pub async fn run<F, Fut, T>(
    policy: &RetryPolicy,
    op: F,
) -> Result<(T, Vec<RetryAttempt>), AnvilError>
where F: FnMut() -> Fut, Fut: Future<Output = Result<T, AnvilError>>,
Expand description

Drives the retry loop for the supplied async operation.

On success returns Ok((value, history)) where history is the list of failed attempts (empty if the first try succeeded). On terminal failure (fatal classification or attempt-count / max-window exhaustion) returns the most-recent error.

Sleep duration between attempt n and n+1 is min(base * factor^(n-1), cap) + uniform_jitter([0, base/2]). Jitter is sourced from OsRng so concurrent processes recovering from a shared outage don’t dogpile.

§Errors

Returns the underlying AnvilError from the last failed attempt when the loop exits without success.