try-again
Retry synchronous or asynchronous operations until they no longer can or need to be retried.
Provides fn retry for retrying synchronous operations.
Provides async fn retry_async for retrying asynchronous operations.
Supports closures and function pointers.
The retried operation may return any type that implements NeedsRetry.
This trait is already implemented for Result, Option and ExitStatus, allowing you to retry common fallible
outcomes.
Synchronous example
use *;
use ;
async
Asynchronous example
use *;
use ;
async
Details
Delay strategies
delayed_by accepts a delay strategy. The delay module provides the following implementations
None: No delay is applied.Fixed: A static delay.ExponentialBackoff: An exponentially increasing delay
All work with std::time::Duration, re-exposed as StdDuration. The IntoStdDuration can be used for a fluent syntax
when defining durations, like in
use try_again::{delay, IntoStdDuration};
delay::Fixed::of(250.millis())
Delay executors
The standard retry and retry_async functions have the following default behavior:
retryputs the current thread to sleep between retries (through the providedThreadSleepexecutor).retry_asyncinstructs the tokio runtime to sleep between retries (through the providedTokioSleepexecutor, requires theasync-tokiofeature (enabled by default)).
The retry_with_options and retry_async_with_options functions can be used to overwrite the standard behavior
with any executor type implementing the DelayExecutor trait.
That way, support for async_std or other asynchronous runtimes could be provided.
MSRV
- As of 0.1.0, the MSRV is
1.56.0 - As of 0.2.0, the MSRV is
1.85.0