pub struct RetryExecutor<E = BoxError> { /* private fields */ }Expand description
Retry executor bound to an error type.
The generic parameter E is the caller’s application error type. The
success type is chosen per call to RetryExecutor::run,
RetryExecutor::run_async, or RetryExecutor::run_async_with_timeout.
Cloning an executor shares the retry decider and listeners through reference
counting.
Implementations§
Source§impl<E> RetryExecutor<E>
impl<E> RetryExecutor<E>
Sourcepub fn builder() -> RetryExecutorBuilder<E>
pub fn builder() -> RetryExecutorBuilder<E>
Creates a retry executor builder.
§Parameters
This function has no parameters.
§Returns
A RetryExecutorBuilder configured with default options and the default
retry-all decider.
§Errors
This function does not return errors.
Sourcepub fn from_options(options: RetryOptions) -> Result<Self, RetryConfigError>
pub fn from_options(options: RetryOptions) -> Result<Self, RetryConfigError>
Creates an executor from options with the default decider.
§Parameters
options: Validated retry options to use for the executor.
§Returns
A RetryExecutor that retries all application errors unless limits stop
execution.
§Errors
Returns RetryConfigError if options fails validation.
Sourcepub fn options(&self) -> &RetryOptions
pub fn options(&self) -> &RetryOptions
Sourcepub fn run<T, F>(&self, operation: F) -> Result<T, RetryError<E>>
pub fn run<T, F>(&self, operation: F) -> Result<T, RetryError<E>>
Runs a synchronous operation with retry.
Loops under global elapsed-time and per-executor attempt limits. Before
each try, exits with an error if the wall-clock budget is already spent
(without calling operation again). Success emits listener events and
returns Ok(T). Failure goes through handle_failure: either
std::thread::sleep then retry, or return a terminal RetryError.
§Parameters
operation: Synchronous operation to execute. It is called once per attempt until it returnsOk, the decider aborts, or retry limits are exhausted.
§Returns
Ok(T) with the operation result, or RetryError preserving the last
application error or timeout metadata.
§Errors
Returns RetryError::Aborted when the decider aborts,
RetryError::AttemptsExceeded when the attempt limit is reached, or
RetryError::MaxElapsedExceeded when the total elapsed-time budget is
exhausted.
§Panics
Propagates any panic raised by operation or by registered listeners.
§Blocking
This method blocks the current thread with std::thread::sleep between
retry attempts when the computed delay is non-zero.
Sourcepub async fn run_async<T, F, Fut>(
&self,
operation: F,
) -> Result<T, RetryError<E>>
pub async fn run_async<T, F, Fut>( &self, operation: F, ) -> Result<T, RetryError<E>>
Runs an asynchronous operation with retry.
Same loop structure as Self::run: checks the global elapsed budget
before each attempt, increments the attempt counter, then runs
operation().await. On failure, handle_failure chooses a backoff
sleep (async) or a terminal RetryError; timing uses Tokio’s timer
instead of blocking std::thread::sleep.
§Parameters
operation: Asynchronous operation factory. It is called once per attempt and must return a fresh future each time.
§Returns
Ok(T) with the operation result, or RetryError preserving the last
application error.
§Errors
Returns RetryError::Aborted when the decider aborts,
RetryError::AttemptsExceeded when the attempt limit is reached, or
RetryError::MaxElapsedExceeded when the total elapsed-time budget is
exhausted.
§Panics
Propagates panics raised by operation, the returned future, or
registered listeners. Tokio may also panic if the future is polled
outside a runtime with a time driver and a non-zero sleep is required.
§Async
Uses tokio::time::sleep between attempts when the computed delay is
non-zero.
Sourcepub async fn run_async_with_timeout<T, F, Fut>(
&self,
attempt_timeout: Duration,
operation: F,
) -> Result<T, RetryError<E>>
pub async fn run_async_with_timeout<T, F, Fut>( &self, attempt_timeout: Duration, operation: F, ) -> Result<T, RetryError<E>>
Runs an asynchronous operation with a timeout for each attempt.
Like Self::run_async, but each attempt is bounded by
tokio::time::timeout(attempt_timeout, operation()). Normal completion
yields the inner Ok/Err. A timeout becomes
RetryAttemptFailure::AttemptTimeout and is fed to handle_failure to
decide retry versus a terminal error, subject to the same global limits.
§Parameters
attempt_timeout: Maximum duration allowed for each individual attempt.operation: Asynchronous operation factory. It is called once per attempt and must return a fresh future each time.
§Returns
Ok(T) with the operation result, or RetryError preserving the last
application error or timeout metadata.
§Errors
Returns RetryError::Aborted when the decider aborts an
application error, RetryError::AttemptsExceeded when the attempt
limit is reached, or RetryError::MaxElapsedExceeded when the total
elapsed-time budget is exhausted. Attempt timeouts are represented as
RetryAttemptFailure::AttemptTimeout and are considered retryable until
limits stop execution.
§Panics
Propagates panics raised by operation, the returned future, or
registered listeners. Tokio may also panic if the future is polled
outside a runtime with a time driver.
§Async
Uses tokio::time::timeout for each attempt and tokio::time::sleep
between retries when the computed delay is non-zero.
Trait Implementations§
Source§impl<E: Clone> Clone for RetryExecutor<E>
impl<E: Clone> Clone for RetryExecutor<E>
Source§fn clone(&self) -> RetryExecutor<E>
fn clone(&self) -> RetryExecutor<E>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more