Crates.io | retry-strategy |
lib.rs | retry-strategy |
version | 0.2.0 |
source | src |
created_at | 2023-04-16 09:00:52.882801 |
updated_at | 2023-10-08 13:25:32.784958 |
description | A better asynchronous retry tool based on Tokio. |
homepage | https://github.com/huster-zhangpeng/retry-strategy |
repository | |
max_upload_size | |
id | 840438 |
size | 18,263 |
A better asynchronous retry tool based on Tokio. The original Tokio::timeout
function ends after a single timeout, but a single timeout may be affected by random factors. For example, establishing a connection or making an HTTP request often requires three timeout retries. If all retries fail, it is considered a final timeout.
Retry-strategy
provides rich and simple timeout settings, allowing you to easily and flexibly set the number of retries, the duration of each timeout, and even more complex strategies. We hope it brings convenience to you.
Add dependencies to your Cargo.toml
:
[dependencies]
retry-strategy = "0.2"
use retry_strategy::prelude::*;
let tcp_connection = retry(
vec![100.ms(), 200.ms(), 300.ms()],
|_n| TcpStream::connect("127.0.0.1:8080")
).await?;