[−][src]Function tryagain::retry_if
pub fn retry_if<B, F, P, T, E>(
mut backoff: B,
func: F,
predicate: P
) -> Result<T, E> where
B: Backoff,
F: Fn() -> Result<T, E>,
P: Fn(&E, u32) -> bool,
Calls the provided function and if an error is returned it is passed to the predicate to determine if the function should be retried when the backoff function allows.
Example
enum Error { Recoverable, Fatal, } fn returns_fatal_error() -> Result<(), Error> { Err(Error::Fatal) } // Returns a Result of Error::Fatal let result = tryagain::retry_if( ExponentialBackoff::default(), returns_fatal_error, |error, _iterations| match error { Error::Fatal => false, // This error isn't recoverable. _ => true, }, );