backon

Trait BlockingRetryable

Source
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 adds retry support for blocking 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>,