SkillAgentSearch skills...

Backon

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

Install / Use

/learn @Xuanwo/Backon
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

BackON   Build Status Latest Version

<img src="https://raw.githubusercontent.com/Xuanwo/backon/main/.github/assets/logo.jpeg" alt="BackON" width="38.2%"/>

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 <a href="./LICENSE">Apache License, Version 2.0</a>.

View on GitHub
GitHub Stars1.0k
CategoryDevelopment
Updated3d ago
Forks54

Languages

Rust

Security Score

100/100

Audited on Mar 21, 2026

No findings