exp_backoff

Crates.ioexp_backoff
lib.rsexp_backoff
version0.1.6
created_at2025-03-13 23:04:35.577842+00
updated_at2025-09-09 02:09:05.408829+00
descriptionJittered exponential backoff implementation in Rust.
homepage
repositoryhttps://github.com/flowerinthenight/backoff-rs
max_upload_size
id1591606
size11,173
(flowerinthenight)

documentation

README

main crates.io docs-rs

Overview

This crate implements jittered backoff. Useful when retrying operations that can potentially fail (i.e. network calls). The implementation is based on this article from the AWS Architecture Blog.

Usage

You can use it like so:

use exp_backoff::*;
use std::error::Error;
use std::{thread, time::Duration};

fn func_that_can_fail() -> Result<(), Box<dyn Error>> {
    if true {
        return Err("some error")?;
    }

    Ok(())
}

fn main() -> Result<(), Box<dyn Error>> {
    let mut bo = BackoffBuilder::new().build();
    for _ in 0..5 {
        match func_that_can_fail() {
            Err(e) => {
                println!("failed: {:?}, retry...", e);
                thread::sleep(Duration::from_nanos(bo.pause()));
            }
            _ => println!("we're okay"),
        }
    }

    Ok(())
}
Commit count: 38

cargo fmt