Function backoff::future::retry_notify[][src]

pub fn retry_notify<I, E, Fn, Fut, B, N>(
    mut backoff: B,
    operation: Fn,
    notify: N
) -> Retry<impl Sleeper, B, N, Fn, Fut>

Notable traits for Retry<S, B, N, Fn, Fut>

impl<S, B, N, Fn, Fut, I, E> Future for Retry<S, B, N, Fn, Fut> where
    S: Sleeper,
    B: Backoff,
    N: Notify<E>,
    Fn: FnMut() -> Fut,
    Fut: Future<Output = Result<I, Error<E>>>, 
type Output = Result<I, E>;
where
    B: Backoff,
    Fn: FnMut() -> Fut,
    Fut: Future<Output = Result<I, Error<E>>>,
    N: Notify<E>, 
This is supported on crate feature futures only.

Retries given operation according to the Backoff policy. Calls notify on failed attempts (in case of Error::Transient). 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.

Async notify

notify can be neither async fn or Future. If you need to perform some async operations inside notify, consider using your runtimes task-spawning functionality.

The reason behind this is that Retry future cannot be responsible for polling notify future, because can easily be dropped before notify is completed. So, considering the fact that most of the time no async operations are required in notify, it's up to the caller to decide how async notify should be performed.

Example

use backoff::backoff::Stop;

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

let err = backoff::future::retry_notify(Stop {}, f, |e, dur| {
    println!("Error happened at {:?}: {}", dur, e)
})
.await
.err()
.unwrap();
assert_eq!(err, "error");