12 releases

0.4.4 Apr 8, 2024
0.4.3 Mar 8, 2024
0.4.2 Feb 21, 2024
0.4.1 May 19, 2023
0.0.2 Apr 14, 2022

#70 in Rust patterns

Download history 51510/week @ 2024-01-03 45347/week @ 2024-01-10 54463/week @ 2024-01-17 43902/week @ 2024-01-24 47202/week @ 2024-01-31 27496/week @ 2024-02-07 32637/week @ 2024-02-14 36190/week @ 2024-02-21 40859/week @ 2024-02-28 34944/week @ 2024-03-06 40826/week @ 2024-03-13 37914/week @ 2024-03-20 33715/week @ 2024-03-27 31723/week @ 2024-04-03 44732/week @ 2024-04-10 25639/week @ 2024-04-17

144,339 downloads per month
Used in 70 crates (12 directly)

Apache-2.0

65KB
1.5K SLoC

backon   Build Status Latest Version

Retry with backoff without effort.


The opposite backoff implementation of the popular backoff.

  • Newer: developed by Rust edition 2021 and latest stable.
  • Cleaner: Iterator based abstraction, easy to use, customization friendly.
  • Easier: Trait based implementations, works like a native function provided by closures.

Quick Start

Retry a blocking function.

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(())
}

Retry an async function.

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

async fn fetch() -> Result<String> {
    Ok(reqwest::get("https://www.rust-lang.org").await?.text().await?)
}

#[tokio::main]
async fn main() -> Result<()> {
    let content = fetch.retry(&ExponentialBuilder::default()).await?;
    println!("fetch succeeded: {}", content);

    Ok(())
}

Contributing

Check out the CONTRIBUTING.md guide for more details on getting started with contributing to this project.

Getting help

Submit issues for bug report or asking questions in discussion.

License

Licensed under Apache License, Version 2.0.

Dependencies

~2.4–4MB
~66K SLoC