#retry #async #retry-backoff #blocking #constant

no-std backon

Make retry like a built-in feature provided by Rust

25 releases (12 stable)

Uses new Rust 2024

1.6.0 Oct 18, 2025
1.5.2 Jul 30, 2025
1.5.1 May 29, 2025
1.4.1 Mar 19, 2025
0.0.2 Apr 14, 2022

#49 in Asynchronous

Download history 1205732/week @ 2026-02-20 1252508/week @ 2026-02-27 1418519/week @ 2026-03-06 1279615/week @ 2026-03-13 1032862/week @ 2026-03-20 1028738/week @ 2026-03-27 1038081/week @ 2026-04-03 1147874/week @ 2026-04-10 1280582/week @ 2026-04-17 1452996/week @ 2026-04-24 1535605/week @ 2026-05-01 1750166/week @ 2026-05-08 1895832/week @ 2026-05-15 1840477/week @ 2026-05-22 1903957/week @ 2026-05-29 1979580/week @ 2026-06-05

7,959,197 downloads per month
Used in 1,692 crates (202 directly)

Apache-2.0

110KB
2K SLoC

BackON   Build Status Latest Version

BackON

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

  • Simple API: Native feel: your_fn.retry(ExponentialBuilder::default()).await.
  • Sync & Async: Supports both blocking and async operations seamlessly.
  • Precise Control: Define when to retry and get notified via when and notify.
  • Custom Strategies: Use built-in backoff strategies (exponential, constant) or define custom ones. Also supports dynamic backoff, such as using the HTTP Retry-After header.
  • Cross-Platform: Works everywhere Rust does, including wasm & no-std.

Quick Start

For more examples, check out the examples.

Retry an async function.

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())
        // Sleep implementation, required if no feature has been enabled
        .sleep(tokio::time::sleep)
        // 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(())
}

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 with exponential backoff
        .retry(ExponentialBuilder::default())
        // Sleep implementation, required if no feature has been enabled
        .sleep(std::thread::sleep)
        // When to retry
        .when(|e| e.to_string() == "EOF")
        // Notify when retrying
        .notify(|err: &anyhow::Error, dur: Duration| {
            println!("retrying {:?} after {:?}", err, dur);
        })
        .call()?;
    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

~0–1MB
~15K SLoC