pub struct RetryPolicy {
pub max_attempts: u32,
pub base_delay: Duration,
pub max_delay: Duration,
}Expand description
Defines a policy for retrying failed operations.
Fields§
§max_attempts: u32The maximum number of attempts to make.
base_delay: DurationThe base delay between retries.
max_delay: DurationThe maximum delay between retries.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn new(max_attempts: u32, base_delay: Duration, max_delay: Duration) -> Self
pub fn new(max_attempts: u32, base_delay: Duration, max_delay: Duration) -> Self
Creates a new RetryPolicy.
§Arguments
max_attempts- The maximum number of attempts.base_delay- The initial delay before the first retry.max_delay- The maximum allowed delay between retries.
Sourcepub fn fast_mailbox() -> Self
pub fn fast_mailbox() -> Self
Creates a fast retry policy suitable for responsive mailbox operations.
Sourcepub fn exponential_backoff(&self, attempt: u32) -> Duration
pub fn exponential_backoff(&self, attempt: u32) -> Duration
Calculates an exponential backoff delay based on the attempt number.
The delay increases exponentially with each attempt, up to max_delay.
§Arguments
attempt- The current attempt number (0-indexed).
Sourcepub fn exponential_backoff_with_jitter(&self, attempt: u32) -> Duration
pub fn exponential_backoff_with_jitter(&self, attempt: u32) -> Duration
Calculates an exponential backoff delay with added jitter.
Jitter helps to prevent “thundering herd” problems when many clients retry simultaneously.
§Arguments
attempt- The current attempt number (0-indexed).
Sourcepub async fn retry_with_jitter<F, T, Fut>(&self, op: F) -> Result<T>
pub async fn retry_with_jitter<F, T, Fut>(&self, op: F) -> Result<T>
Retries an asynchronous operation using the defined retry policy.
The operation op will be retried max_attempts times, with exponential
backoff and jitter between attempts.
§Arguments
op- A closure that returns aFuturerepresenting the operation to retry.
§Returns
The Result of the operation if successful, or the last error encountered.
Auto Trait Implementations§
impl Freeze for RetryPolicy
impl RefUnwindSafe for RetryPolicy
impl Send for RetryPolicy
impl Sync for RetryPolicy
impl Unpin for RetryPolicy
impl UnwindSafe for RetryPolicy
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more