pub struct Backoff { /* private fields */ }Expand description
An exponential-backoff policy.
Implementations§
Source§impl Backoff
impl Backoff
Sourcepub const fn new(base_ms: u64, max_ms: u64, max_retries: u32) -> Backoff
pub const fn new(base_ms: u64, max_ms: u64, max_retries: u32) -> Backoff
A policy starting at base_ms, doubling each attempt, capped at max_ms,
giving up after max_retries.
const so a caller can state its policy as a constant next to the
reasoning for it, rather than rebuilding one per call.
Sourcepub fn delay_ms(&self, attempt: u32) -> u64
pub fn delay_ms(&self, attempt: u32) -> u64
The (un-jittered) delay before retry attempt (0-based): base * 2^attempt,
saturating and capped at max_ms.
Sourcepub fn jittered_delay_ms(&self, attempt: u32, rand01: f64) -> u64
pub fn jittered_delay_ms(&self, attempt: u32, rand01: f64) -> u64
The full-jitter delay for attempt: a uniform sample in [0, delay],
given a random fraction rand01 in [0, 1).
Sourcepub fn should_retry(&self, attempt: u32) -> bool
pub fn should_retry(&self, attempt: u32) -> bool
Whether an attempt (0-based) should be retried.
Sourcepub fn max_retries(&self) -> u32
pub fn max_retries(&self) -> u32
The configured maximum number of retries.
Trait Implementations§
impl Copy for Backoff
impl Eq for Backoff
impl StructuralPartialEq for Backoff
Auto Trait Implementations§
impl Freeze for Backoff
impl RefUnwindSafe for Backoff
impl Send for Backoff
impl Sync for Backoff
impl Unpin for Backoff
impl UnsafeUnpin for Backoff
impl UnwindSafe for Backoff
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
Mutably borrows from an owned value. Read more
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> ⓘ
Converts
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> ⓘ
Converts
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