attempt 0.1.0

Attempt to do something over and over and over and over and...
Documentation
  • Coverage
  • 91.67%
    11 out of 12 items documented1 out of 10 items with examples
  • Size
  • Source code size: 19.14 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.44 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • oatmilkcat/attempt
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • TylerLafayette

attempt

Crates.io Documentation

A utility crate for retrying failable operations with various configuration options.

Example

use attempt::Attempt;

fn fetch_data_from_unreliable_api() -> Result<Data, Error> {
    // Fetch data from an API which randomly fails for no reason.
    // We've all dealt with one of these.
}

fn main() {
    let res: Result<Data, Error> =
        Attempt::to(fetch_data_from_unreliable_api)
            .delay(std::time::Duration::from_secs(1))
            .max_tries(1000)
            .run();

    // Be careful with this one.
    let res: Data =
        Attempt::infinitely(fetch_data_from_unreliable_api);

    // "Sensible" default of 10 max tries with an increasing delay between
    //  each attempt starting at 500ms.
    let res: Result<Data, Error> = Attempt::to(fetch_data_from_unreliable_api).run();
}

async fn fetch_data_from_unreliable_api_async() -> Result<Data, Error> {
    // Fetch data from an API which randomly fails for no reason, but do it async!
}

async fn async_attempt_example() -> Result<Data, Error> {
    Attempt::to(fetch_data_from_unreliable_api_async)
        .delay(std::time::Duration::from_secs(1))
        .max_tries(1000)
        .run_async()
        .await
}