pub struct RetryStrategy { /* private fields */ }Expand description
Configurable exponential-backoff policy.
Defaults: 1-second base delay, 30-second maximum delay, 12 attempts.
Builders (with_base_delay,
with_max_delay,
with_max_attempts) return the updated strategy.
Implementations§
Source§impl RetryStrategy
impl RetryStrategy
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a strategy with 1-second base delay, 30-second max delay, and 12 attempts.
Sourcepub fn with_base_delay(self, d: Duration) -> Self
pub fn with_base_delay(self, d: Duration) -> Self
Sets the initial delay before the first retry.
Sourcepub fn with_max_delay(self, d: Duration) -> Self
pub fn with_max_delay(self, d: Duration) -> Self
Sets the upper bound for the doubling delay.
Sourcepub fn with_max_attempts(self, n: usize) -> Self
pub fn with_max_attempts(self, n: usize) -> Self
Sets how many total attempts are made before giving up.
Sourcepub async fn with_exponential_backoff<F, T, E>(
&self,
f: F,
) -> Result<T, RetryExhaustedError>
pub async fn with_exponential_backoff<F, T, E>( &self, f: F, ) -> Result<T, RetryExhaustedError>
Runs a boxed-future operation with exponential backoff.
F is the closure producing each attempt’s boxed future, T the success
value, and E the per-attempt error (converted to text on exhaustion).
Returns the first success, or RetryExhaustedError after max_attempts.
Sourcepub async fn retry<F, Fut, T, E>(&self, op: F) -> Result<T, RetryExhaustedError>
pub async fn retry<F, Fut, T, E>(&self, op: F) -> Result<T, RetryExhaustedError>
Runs an operation returning a future with exponential backoff.
F is the closure producing each attempt, Fut its future, T the
success value, and E the per-attempt error (converted to text on
exhaustion). Returns the first success, or RetryExhaustedError
after max_attempts.
Trait Implementations§
Source§impl Clone for RetryStrategy
impl Clone for RetryStrategy
Auto Trait Implementations§
impl Freeze for RetryStrategy
impl RefUnwindSafe for RetryStrategy
impl Send for RetryStrategy
impl Sync for RetryStrategy
impl Unpin for RetryStrategy
impl UnsafeUnpin for RetryStrategy
impl UnwindSafe for RetryStrategy
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> 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