A retry and backoff mechanism for std::future::Future
.
toml
[dependencies]
backoff-futures = "0.1"
cargo-edit
cargo add backoff-futures
```rust
fn isahcerrortobackoff(err: isahc::Error) -> backoff::Error
async fn getexamplecontents() -> Result
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 getexamplecontentswithretry() -> Result
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
})
} ```