Skip to main content

WithRetry

Trait WithRetry 

Source
pub trait WithRetry<T, E>: Sized {
    // Required method
    fn with_retry(
        self,
        schedule: RetrySchedule,
    ) -> impl Future<Output = Result<T, E>> + Send
       where Self: Send,
             T: Send,
             E: Send;
}
Expand description

Postfix retry combinator over an async operation factory — the general retry engine (e.g. for retrying a whole webhook handler). The receiver must be a factory (FnMut() -> Future) rather than a Future, because a Future is single-use — every retry attempt needs a freshly-produced one.

ⓘ
(|| handler())
    .with_retry(RetrySchedule::transient())
    .await

Behaviour: up to schedule.max_attempts attempts. On Ok, returns immediately. On Err whose Retryable::is_transient is false, returns immediately. On transient Err, sleeps the schedule’s backoff and retries; the last attempt’s error is returned if all fail.

Required Methods§

Source

fn with_retry( self, schedule: RetrySchedule, ) -> impl Future<Output = Result<T, E>> + Send
where Self: Send, T: Send, E: Send,

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<F, Fut, T, E> WithRetry<T, E> for F
where F: FnMut() -> Fut, Fut: Future<Output = Result<T, E>> + Send, E: Retryable + Display,