#backoff #exponential #futures

deprecated backoff-futures

A retry and backoff mechanism for std::future::Future. DEPRECATED: see backoff::future

6 releases

0.3.2 Jul 14, 2020
0.3.1 Jul 14, 2020
0.3.0 Jun 12, 2020
0.2.0 Nov 27, 2019
0.1.1 Aug 15, 2019

#5 in #exponential

Download history 15/week @ 2023-10-19 27/week @ 2023-10-26 16/week @ 2023-11-02 26/week @ 2023-11-09 42/week @ 2023-11-16 31/week @ 2023-11-23 36/week @ 2023-11-30 47/week @ 2023-12-07 30/week @ 2023-12-14 31/week @ 2023-12-21 4/week @ 2023-12-28 10/week @ 2024-01-04 11/week @ 2024-01-11 30/week @ 2024-01-18 33/week @ 2024-01-25 32/week @ 2024-02-01

108 downloads per month
Used in tokkit

MIT license

13KB
158 lines

backoff-futures

Build status crates.io docs.rs License: MIT

A retry and backoff mechanism for std::future::Future.

Documentation

Adding as a dependency

Manually

[dependencies]
backoff-futures = "0.1"

With cargo-edit

cargo add backoff-futures

Usage

#![feature(async_await)]

fn isahc_error_to_backoff(err: isahc::Error) -> backoff::Error<isahc::Error> {
    match err {
        isahc::Error::Aborted | isahc::Error::Io(_) | isahc::Error::Timeout =>
            backoff::Error::Transient(err),
        _ =>
            backoff::Error::Permanent(err)
    }
}

async fn get_example_contents() -> Result<String, backoff::Error<isahc::Error>> {
    use isahc::ResponseExt;

    let mut response = isahc::get_async("https://example.org")
        .await
        .map_err(isahc_error_to_backoff)?;

    response
        .text_async()
        .await
        .map_err(|err: std::io::Error| backoff::Error::Transient(isahc::Error::Io(err)))
}

async fn get_example_contents_with_retry() -> Result<String, isahc::Error> {
    use backoff_futures::BackoffExt;

    let mut backoff = backoff::ExponentialBackoff::default();
    get_example_contents.with_backoff(&mut backoff)
        .await
        .map_err(|err| match err {
            backoff::Error::Transient(err) | backoff::Error::Permanent(err) => err
        })
}

License

MIT

Dependencies

~4.5MB
~77K SLoC