pub trait BlockingRetryable<B: BackoffBuilder, T, E, F: FnMut() -> Result<T, E>> {
    // Required method
    fn retry(self, builder: &B) -> BlockingRetry<B::Backoff, T, E, F>;
}
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::Backoff, T, E, F>

Generate a new retry

Implementors§

source§

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