Function backoff::future::retry_notify [−][src]
pub fn retry_notify<I, E, Fn, B, N>(
backoff: B,
operation: Fn,
notify: N
) -> Retry<B, N, Fn, Fn::Fut> where
B: Backoff,
Fn: FutureOperation<I, E>,
N: Notify<E>,
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.
Async notify
notify
can be neither async fn
or Future
. If you need to perform some async
operations inside notify
, consider to use tokio::spawn
or async_std::task::spawn
for that.
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::{future, backoff::Stop}; async fn f() -> Result<(), backoff::Error<&'static str>> { // Business logic... Err(backoff::Error::Transient("error")) } future::retry_notify(Stop {}, f, |e, dur| println!("Error happened at {:?}: {}", dur, e)) .await .err() .unwrap();