Trait backoff::future::FutureOperation [−][src]
FutureOperation
is a Future
operation that can be retried if it fails with the
provided Backoff
.
Note, that this should not be a Future
itself, but rather something producing a
Future
(a closure, for example).
Associated Types
type Fut: Future<Output = Result<I, Error<E>>>
[src]
Type of Future
that this FutureOperation
produces.
Required methods
fn call_op(&mut self) -> Self::Fut
[src]
Calls this FutureOperation
returning a Future
to be executed.
Provided methods
fn retry<B>(self, backoff: B) -> Retry<B, NoopNotify, Self, Self::Fut> where
B: Backoff,
Self: Sized,
[src]
B: Backoff,
Self: Sized,
Retries this FutureOperation
according to the Backoff
policy.
Backoff
is reset before it is used.
Example
use backoff::{future::FutureOperation as _, ExponentialBackoff}; async fn f() -> Result<(), backoff::Error<&'static str>> { // Business logic... Err(backoff::Error::Permanent("error")) } f.retry(ExponentialBackoff::default()).await.err().unwrap();
fn retry_notify<B, N>(
self,
backoff: B,
notify: N
) -> Retry<B, N, Self, Self::Fut> where
B: Backoff,
N: Notify<E>,
Self: Sized,
[src]
self,
backoff: B,
notify: N
) -> Retry<B, N, Self, Self::Fut> where
B: Backoff,
N: Notify<E>,
Self: Sized,
Retries this FutureOperation
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::FutureOperation as _, backoff::Stop}; async fn f() -> Result<(), backoff::Error<&'static str>> { // Business logic... Err(backoff::Error::Transient("error")) } f.retry_notify(Stop {}, |e, dur| println!("Error happened at {:?}: {}", dur, e)) .await .err() .unwrap();
Implementors
impl<I, E, Fn, Fut> FutureOperation<I, E> for Fn where
Fn: FnMut() -> Fut,
Fut: Future<Output = Result<I, Error<E>>>,
[src]
Fn: FnMut() -> Fut,
Fut: Future<Output = Result<I, Error<E>>>,