Trait backoff::Operation [] [src]

pub trait Operation<T, E> {
    fn call_op(&mut self) -> Result<T, Error<E>>;

    fn retry<B>(&mut self, backoff: &mut B) -> Result<T, Error<E>>
    where
        B: Backoff
, { ... } fn retry_notify<B, N>(
        &mut self,
        backoff: &mut B,
        notify: N
    ) -> Result<T, Error<E>>
    where
        N: Notify<E>,
        B: Backoff
, { ... } }

Operation is an operation that can be retried if it fails.

Operation is an operation that can be retried if it fails.

Required Methods

call_op implements the effective operation.

Provided Methods

Retries this operation according to the backoff policy. backoff is reset before it is used.

Examples

let mut f = || -> Result<(), Error<&str>> {
    // Business logic...
    // Give up.
    Err(Error::Permanent("error"))
};

let mut backoff = ExponentialBackoff::default();
let _ = f.retry(&mut backoff).err().unwrap();

Retries this operation according to the backoff policy. Calls notify on failed attempts (in case of transient errors). backoff is reset before it is used.

Examples

let notify = |err, dur| { println!("Error happened at {:?}: {}", dur, err); };
let mut f = || -> Result<(), Error<&str>> {
    // Business logic...
    Err(Error::Transient("error"))
};

let mut backoff = Stop{};
let _ = f.retry_notify(&mut backoff, notify).err().unwrap();

Implementors