BackON 1.0.0: Make retry like a built-in feature provided by Rust.

265 points xuanwo

Hello, everyone. I'm happy to announce that BackON has its 1.0.0 release now!

Backon was first introduced in Backon: Maybe the most elegant retry library ever and has received a lot of feedback from there. So I believe it's a great place for its 1.0.0 release.

Compared to the previous version, BackON now supports async runtime agnostic, retrying both blocking and async functions, and retrying with functions that need to take &mut self.

I hope you will love it!


As a quick start:

use anyhow::Result;
use backon::ExponentialBuilder;
use backon::Retryable;

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

#[tokio::main]
async fn main() -> Result<()> {
    let content = fetch
        // Retry with exponential backoff
        .retry(ExponentialBuilder::default())
        // When to retry
        .when(|e| e.to_string() == "EOF")
        // Notify when retrying
        .notify(|err: &anyhow::Error, dur: Duration| {
            println!("retrying {:?} after {:?}", err, dur);
        })
        .await?;
    println!("fetch succeeded: {}", content);

    Ok(())
}