Crates.io | tryhard |
lib.rs | tryhard |
version | 0.5.1 |
source | src |
created_at | 2020-11-23 14:21:30.019365 |
updated_at | 2023-08-23 20:06:53.291914 |
description | Easily retry futures |
homepage | https://github.com/EmbarkStudios/tryhard |
repository | https://github.com/EmbarkStudios/tryhard |
max_upload_size | |
id | 315397 |
size | 65,974 |
tryhard
makes it easy to retry futures that might fail. You can control the number of retries, the backoff strategy, and the max duration.
First imagine you have some async function that can fail:
async fn read_file(path: &str) -> Result<String, std::io::Error> {
// ...
}
Calling that function and retrying at most 10 times with no delay between attempts can be done like so:
tryhard::retry_fn(|| read_file("Cargo.toml"))
.retries(10)
.await?;
You can also retry with a fixed delay between attempts:
tryhard::retry_fn(|| read_file("Cargo.toml"))
.retries(10)
.fixed_backoff(Duration::from_millis(100))
.await?;
Or exponential backoff, where the delay doubles each time, with a max delay of 1 second:
tryhard::retry_fn(|| read_file("Cargo.toml"))
.retries(10)
.exponential_backoff(Duration::from_millis(10))
.max_delay(Duration::from_secs(1))
.await?;
See the docs for more details.
We welcome community contributions to this project.
Please read our Contributor Guide for more information on how to get started.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.