pub trait BlockingRetryable<B, T, E, F>where
    B: BackoffBuilder,
    F: FnMut() -> Result<T, E>,{
    // Required method
    fn retry(
        self,
        builder: &B
    ) -> BlockingRetry<<B as BackoffBuilder>::Backoff, T, E, F, fn(_: &E) -> bool, fn(_: &E, _: Duration)>;
}
Expand description

BlockingRetryable will add retry support for functions.

For example:

  • Functions without extra args:
fn fetch() -> Result<String> {
    Ok("hello, world!".to_string())
}
  • Closures
|| {
    Ok("hello, world!".to_string())
}

Example

use anyhow::Result;
use backon::BlockingRetryable;
use backon::ExponentialBuilder;

fn fetch() -> Result<String> {
    Ok("hello, world!".to_string())
}

fn main() -> Result<()> {
    let content = fetch.retry(&ExponentialBuilder::default()).call()?;
    println!("fetch succeeded: {}", content);

    Ok(())
}

Required Methods§

source

fn retry( self, builder: &B ) -> BlockingRetry<<B as BackoffBuilder>::Backoff, T, E, F, fn(_: &E) -> bool, fn(_: &E, _: Duration)>

Generate a new retry

Implementors§

source§

impl<B, T, E, F> BlockingRetryable<B, T, E, F> for Fwhere B: BackoffBuilder, F: FnMut() -> Result<T, E>,