pub struct RetryManager<E> { /* private fields */ }Expand description
A stateless, thread-safe retry manager for network operations.
Each execution maintains independent backoff and elapsed-time state.
Implementations§
Source§impl<E> RetryManager<E>where
E: Error,
impl<E> RetryManager<E>where
E: Error,
Sourcepub const fn new(config: RetryConfig) -> Self
pub const fn new(config: RetryConfig) -> Self
Creates a new retry manager with the given configuration.
Sourcepub async fn execute_with_retry_inner<F, Fut, T>(
&self,
operation_name: &str,
operation: F,
should_retry: impl Fn(&E) -> bool,
create_error: impl Fn(RetryError) -> E,
cancel: Option<&CancellationToken>,
) -> Result<T, E>
pub async fn execute_with_retry_inner<F, Fut, T>( &self, operation_name: &str, operation: F, should_retry: impl Fn(&E) -> bool, create_error: impl Fn(RetryError) -> E, cancel: Option<&CancellationToken>, ) -> Result<T, E>
Executes an operation with retry logic and optional cancellation.
Cancellation is checked at three points:
- Before each operation attempt.
- During operation execution through
tokio::select!. - During retry delays.
Cancellation mid-execution takes effect immediately by dropping the in-flight operation future. For non-idempotent operations (e.g. an order already on the wire) the outcome of the abandoned attempt is unknown to the caller.
§Errors
Returns an error if the operation fails after exhausting all retries, if the operation times out, if creating the backoff state fails, or if canceled.
Sourcepub async fn execute_with_retry<F, Fut, T>(
&self,
operation_name: &str,
operation: F,
should_retry: impl Fn(&E) -> bool,
create_error: impl Fn(RetryError) -> E,
) -> Result<T, E>
pub async fn execute_with_retry<F, Fut, T>( &self, operation_name: &str, operation: F, should_retry: impl Fn(&E) -> bool, create_error: impl Fn(RetryError) -> E, ) -> Result<T, E>
Executes an operation with retry logic.
§Errors
Returns an error if the operation fails after exhausting all retries, if the operation times out, or if creating the backoff state fails.
Sourcepub async fn execute_with_retry_with_delay<F, Fut, T>(
&self,
operation_name: &str,
operation: F,
should_retry: impl Fn(&E) -> bool,
retry_delay: impl Fn(&E) -> Option<Duration>,
create_error: impl Fn(RetryError) -> E,
) -> Result<T, E>
pub async fn execute_with_retry_with_delay<F, Fut, T>( &self, operation_name: &str, operation: F, should_retry: impl Fn(&E) -> bool, retry_delay: impl Fn(&E) -> Option<Duration>, create_error: impl Fn(RetryError) -> E, ) -> Result<T, E>
Executes an operation with retry logic and an error-provided minimum retry delay.
The delay runs between attempts and does not consume the per-operation timeout. If the required delay cannot fit within the remaining retry budget, the original error is returned.
§Errors
Returns an error if the operation fails after exhausting all retries, if the operation times out, or if creating the backoff state fails.
Sourcepub async fn execute_with_retry_with_cancel<F, Fut, T>(
&self,
operation_name: &str,
operation: F,
should_retry: impl Fn(&E) -> bool,
create_error: impl Fn(RetryError) -> E,
cancellation_token: &CancellationToken,
) -> Result<T, E>
pub async fn execute_with_retry_with_cancel<F, Fut, T>( &self, operation_name: &str, operation: F, should_retry: impl Fn(&E) -> bool, create_error: impl Fn(RetryError) -> E, cancellation_token: &CancellationToken, ) -> Result<T, E>
Executes an operation with retry logic and cancellation support.
§Errors
Returns an error if the operation fails after exhausting all retries, if the operation times out, if creating the backoff state fails, or if canceled.
Trait Implementations§
Source§impl<E: Clone> Clone for RetryManager<E>
impl<E: Clone> Clone for RetryManager<E>
Source§fn clone(&self) -> RetryManager<E>
fn clone(&self) -> RetryManager<E>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more