zebp / tryagain

A library to try things again if they fail

Home Page:https://docs.rs/tryagain

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tryagain

Docs.rs Crates.io Unlicense

tryagain is a crate to try things again if they fail inspired by backoff that offers an easier way to cancel retry attemps and uses a non-blocking async implementation. tryagain works with both tokio and async-std through the use of the feature flags runtime-tokio and runtime-async-std.

Sync example

let counter = RefCell::new(0);
let fails_four_times = || {
    let mut counter = counter.borrow_mut();
    *counter += 1;

    if *counter < 5 {
        Err(*counter)
    } else {
        Ok(())
    }
};

tryagain::retry(ImmediateBackoff, fails_four_times);

Async example

let counter = RefCell::new(0);
let fails_four_times = || async {
    let mut counter = counter.borrow_mut();
    *counter += 1;

    if *counter < 5 {
        Err(*counter)
    } else {
        Ok(())
    }
};

tryagain::future::retry(ImmediateBackoff, fails_four_times).await;

About

A library to try things again if they fail

https://docs.rs/tryagain

License:The Unlicense


Languages

Language:Rust 100.0%