tokio-retry2
Forked from https://github.com/srijs/rust-tokio-retry to keep it up-to-date
Extensible, asynchronous retry behaviours for the ecosystem of tokio libraries.
Installation
Add this to your Cargo.toml
:
[]
= { = "0.5", = ["jitter"] }
Examples
use ;
use ;
async
async
Or, to retry with a notification function:
use ;
use ;
async
async
Early Exit and Error Handling
Actions must return a RetryError
that can wrap any other error type. There are 2 RetryError
error trypes:
Permanent
, which receives an error and brakes the retry loop. It can be constructed manually or with auxiliary functionsRetryError::permanent(e: E)
, that returns aRetryError::Permanent<E>
, orRetryError::to_permanent(e: E)
, that returns anErr(RetryError::Permanent<E>)
.Transient
, which is the Default error for the loop. It has 2 modes:RetryError::transient(e: E)
andRetryError::to_transient(e: E)
, that return aRetryError::Transient<E>
, which is an error that triggers the retry strategy.RetryError::retry_after(e: E, duration: std::time::Duration)
andRetryError::to_retry_after(e: E, duration: std::time::Duration)
, that return aRetryError::Transient<E>
, which is an error that triggers the retry strategy after the specified duration.
- Thet is also the trait
MapErr
that possesses 2 auxiliary functions that map the current function Result toResult<T, RetryError<E>>
:fn map_transient_err(self) -> Result<T, RetryError<E>>;
fn map_permanent_err(self) -> Result<T, RetryError<E>>;
- Using the
?
operator on anOption
type will always propagate aRetryError::Transient<E>
with no extra duration.