rama::utils::backoff

Trait Backoff

pub trait Backoff:
    Send
    + Sync
    + 'static {
    // Required methods
    fn next_backoff(&self) -> impl Future<Output = bool> + Send;
    fn reset(&self) -> impl Future<Output = ()> + Send;
}
Expand description

A backoff trait where a single mutable reference represents a single backoff session.

Backoffs are expected to implement Clone and make sure when cloning too reset any state within the backoff, to ensure that each backoff clone has its own independent state, which starts from a clean slate.

Required Methods§

fn next_backoff(&self) -> impl Future<Output = bool> + Send

Initiate the next backoff in the sequence. Return false in case no backoff is possible anymore (e.g. max retries).

It is expected that the backoff implementation resets itself prior to returning false.

fn reset(&self) -> impl Future<Output = ()> + Send

Reset the backoff to its initial state.

Note that Backoff::next_backoff resets automatically when it returns false, so this method should only be used when the backoff needs to be reset before it has completed.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl Backoff for ()

§

async fn next_backoff(&self) -> bool

§

async fn reset(&self)

§

impl<T> Backoff for Option<T>
where T: Backoff,

§

async fn next_backoff(&self) -> bool

§

async fn reset(&self)

§

impl<T> Backoff for Arc<T>
where T: Backoff,

§

fn next_backoff(&self) -> impl Future<Output = bool> + Send

§

fn reset(&self) -> impl Future<Output = ()> + Send

Implementors§

§

impl Backoff for Undefined

§

impl<F, R> Backoff for ExponentialBackoff<F, R>
where R: Rng, F: Send + Sync + 'static,