[][src]Trait backoff::Operation

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

fn call_op(&mut self) -> Result<T, Error<E>>

call_op implements the effective operation.

Loading content...

Provided methods

fn retry<B>(&mut self, backoff: &mut B) -> Result<T, Error<E>> where
    B: Backoff

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();

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

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();
Loading content...

Implementors

impl<T, E, F> Operation<T, E> for F where
    F: FnMut() -> Result<T, Error<E>>, 
[src]

Loading content...