Skip to main content

RetryPolicy

Trait RetryPolicy 

Source
pub trait RetryPolicy: MaybeSend + MaybeSync {
    // Required method
    fn retry<'a>(
        &'a self,
        attempt: u32,
        outcome: &RetryOutcome<'_>,
    ) -> Option<Pin<Box<dyn Future<Output = ()> + Send + 'a>>>;
}
Expand description

A caller-supplied retry policy: it decides whether to retry and, crucially, provides the wait.

RetryBackend calls retry after each attempt. Returning Some(future) means “retry after awaiting this future”; the future carries the backoff delay, built with the caller’s own async timer (e.g. tokio::time::sleep) — this is how timing stays caller-owned and the runtime avoids a tokio dependency. Returning None stops retrying and the last outcome is returned.

Required Methods§

Source

fn retry<'a>( &'a self, attempt: u32, outcome: &RetryOutcome<'_>, ) -> Option<Pin<Box<dyn Future<Output = ()> + Send + 'a>>>

Called after attempt attempt (0-based) produced outcome. Return Some(wait) to retry after awaiting wait (which encapsulates the backoff delay using the caller’s timer), or None to stop and return the outcome. The wait is a [RetryWait] — a boxed future that is Send on native and !Send on wasm32.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§