backoff::future

Function retry

Source
pub fn retry<I, E, Fn, Fut, B>(
    backoff: B,
    operation: Fn,
) -> Retry<impl Sleeper, B, NoopNotify, Fn, Fut> 
where B: Backoff, Fn: FnMut() -> Fut, Fut: Future<Output = Result<I, Error<E>>>,
Expand description

Retries given operation according to the Backoff policy Backoff is reset before it is used. The returned future can be spawned onto a compatible runtime.

Only available through the tokio and async-std feature flags.

§Example

use backoff::ExponentialBackoff;

async fn f() -> Result<(), backoff::Error<&'static str>> {
    // Business logic...
    Err(backoff::Error::Permanent("error"))
}

backoff::future::retry(ExponentialBackoff::default(), f).await.err().unwrap();