pub struct Retry<E = BoxError> { /* private fields */ }Expand description
Retry policy and executor bound to an operation error type.
The generic parameter E is the caller’s operation error type. Cloning a
retry policy shares all registered functors through reference-counted
rs-function wrappers.
Implementations§
Source§impl<E> Retry<E>
Source of an effective attempt timeout.
impl<E> Retry<E>
Source of an effective attempt timeout.
Sourcepub fn builder() -> RetryBuilder<E>
pub fn builder() -> RetryBuilder<E>
Sourcepub fn from_options(options: RetryOptions) -> Result<Self, RetryConfigError>
pub fn from_options(options: RetryOptions) -> Result<Self, RetryConfigError>
Creates a retry policy from options.
§Parameters
options: Retry options to validate and install.
§Returns
A retry policy using the default listener set.
§Errors
Returns RetryConfigError if the options are invalid.
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.
§Parameters
operation: Operation called once per attempt until it succeeds or the retry flow stops.
§Returns
Ok(T) with the operation value, or RetryError when retrying stops.
§Panics
Propagates operation panics and listener panics unless listener panic isolation is enabled.
§Blocking
Blocks the current thread with std::thread::sleep between attempts when
a non-zero retry delay is selected.
§Elapsed Budget
max_operation_elapsed counts only user operation execution time.
max_total_elapsed counts monotonic retry-flow time, including
operation execution, retry sleep, retry-after sleep, and retry
control-path listener time. This synchronous mode cannot interrupt an
already-running operation; it checks budgets before attempts and after
failed attempts. If attempt_timeout is configured, this method returns
RetryErrorReason::UnsupportedOperation because timeout enforcement
requires worker-thread or async execution.
Sourcepub fn run_in_worker<T, F>(&self, operation: F) -> Result<T, RetryError<E>>
pub fn run_in_worker<T, F>(&self, operation: F) -> Result<T, RetryError<E>>
Runs a blocking operation with retry inside worker-thread attempts.
Each attempt runs on a worker thread. Worker panics are captured as
AttemptFailure::Panic. Worker-spawn failures are reported as
AttemptFailure::Executor. If the effective timeout expires, the retry
executor stops waiting and marks the attempt’s AttemptCancelToken as
cancelled. It then waits up to RetryOptions::worker_cancel_grace for
the worker to exit. Configured attempt-timeout expirations continue
according to AttemptTimeoutPolicy only when the worker exits within
that grace period; otherwise the retry flow stops with
RetryErrorReason::WorkerStillRunning. Elapsed-budget expirations stop
with RetryErrorReason::MaxOperationElapsedExceeded or
RetryErrorReason::MaxTotalElapsedExceeded.
§Parameters
operation: Thread-safe operation called once per attempt. It receives a cooperative cancellation token for that attempt.
§Returns
Ok(T) with the operation value, or RetryError when retrying stops.
§Panics
Does not propagate operation panics. Listener panic behavior follows this retry policy’s listener isolation setting.
§Blocking
Blocks the current thread while waiting for each worker result or timeout and while sleeping between retry attempts.
§Elapsed Budget
max_operation_elapsed counts only user operation execution time.
max_total_elapsed counts monotonic retry-flow time. Worker attempts use
the shortest of configured attempt timeout, remaining
max-operation-elapsed budget, and remaining max-total-elapsed budget as
their effective timeout.
Sourcepub fn run_blocking_with_timeout<T, F>(
&self,
operation: F,
) -> Result<T, RetryError<E>>
pub fn run_blocking_with_timeout<T, F>( &self, operation: F, ) -> Result<T, RetryError<E>>
Runs a blocking operation with retry and per-attempt timeout isolation.
This method is a compatibility alias for Retry::run_in_worker. It
also runs attempts in worker threads when no timeout is configured, so
worker panics are reported as AttemptFailure::Panic instead of
unwinding through the caller. Worker-spawn failures are reported as
AttemptFailure::Executor.
§Parameters
operation: Thread-safe operation called once per attempt. It receives a cooperative cancellation token for that attempt.
§Returns
Ok(T) with the operation value, or RetryError when retrying stops.
§Panics
Does not propagate operation panics. Listener panic behavior follows this retry policy’s listener isolation setting.
§Blocking
Blocks the current thread while waiting for each worker result or timeout and while sleeping between retry attempts.
§Elapsed Budget
max_operation_elapsed counts only user operation execution time.
max_total_elapsed counts monotonic retry-flow time. Worker attempts use
the shortest of configured attempt timeout, remaining
max-operation-elapsed budget, and remaining max-total-elapsed budget as
their effective timeout.
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.
§Parameters
operation: Factory returning a fresh future for each attempt.
§Returns
Ok(T) with the operation value, or RetryError when retrying stops.
§Panics
Propagates operation panics from the current async task. They are not
converted to AttemptFailure::Panic because run_async does not
create an isolation boundary. Listener panics are propagated unless
listener panic isolation is enabled. Tokio may panic if timer APIs are
used outside a runtime with a time driver.
§Elapsed Budget
max_operation_elapsed counts only user operation execution time.
max_total_elapsed counts monotonic retry-flow time. Async attempts use
the shortest of configured attempt timeout, remaining
max-operation-elapsed budget, and remaining max-total-elapsed budget as
their effective timeout.
Trait Implementations§
Auto Trait Implementations§
impl<E> Freeze for Retry<E>
impl<E = Box<dyn Error + Sync + Send>> !RefUnwindSafe for Retry<E>
impl<E> Send for Retry<E>
impl<E> Sync for Retry<E>
impl<E> Unpin for Retry<E>
impl<E> UnsafeUnpin for Retry<E>
impl<E = Box<dyn Error + Sync + Send>> !UnwindSafe for Retry<E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
Source§fn into_config_default(self) -> T
fn into_config_default(self) -> T
T.