Skip to main content

MaxElapsedTime

Struct MaxElapsedTime 

Source
pub struct MaxElapsedTime<P, C: Clock> { /* private fields */ }
Expand description

Stops retrying once a wall-clock budget has elapsed.

On the first call to next_delay, the wrapper snapshots the current instant from the injected Clock. Once max_elapsed has passed since that snapshot, it returns None. Construct via PolicyExt::max_elapsed_time.

Because the time source is injected, this works identically against a real system clock and a fully virtual test clock.

§The budget gates starting a retry, not finishing it

The elapsed-time check happens when a delay is requested, and the returned delay is not clamped against the remaining budget. So a retry that is permitted just before the budget expires will still sleep for its full delay, pushing the real elapsed time past max_elapsed by up to one interval. In other words, max_elapsed bounds when the last retry begins, not when all waiting is guaranteed to be done. Pair it with WithMaxDelay if you need to cap that overshoot.

Implementations§

Source§

impl<P, C: Clock> MaxElapsedTime<P, C>

Source

pub const fn new(inner: P, clock: C, max_elapsed: Duration) -> Self

Wrap inner, giving up after max_elapsed measured by clock.

Source

pub fn inner(&self) -> &P

Borrow the wrapped policy.

Source

pub fn into_inner(self) -> P

Consume the wrapper and return the inner policy.

Trait Implementations§

Source§

impl<P: BackoffPolicy, C: Clock> BackoffPolicy for MaxElapsedTime<P, C>

Source§

fn next_delay(&mut self) -> Option<Duration>

Advance the state machine and return the delay to wait before the next attempt. Read more
Source§

fn reset(&mut self)

Rewind the state machine to its initial condition so it can be reused.
Source§

impl<P: Clone, C: Clone + Clock> Clone for MaxElapsedTime<P, C>
where C::Instant: Clone,

Source§

fn clone(&self) -> MaxElapsedTime<P, C>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: Copy, C: Copy + Clock> Copy for MaxElapsedTime<P, C>
where C::Instant: Copy,

Source§

impl<P: Debug, C: Debug + Clock> Debug for MaxElapsedTime<P, C>
where C::Instant: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<P, C> Freeze for MaxElapsedTime<P, C>
where P: Freeze, C: Freeze, <C as Clock>::Instant: Freeze,

§

impl<P, C> RefUnwindSafe for MaxElapsedTime<P, C>

§

impl<P, C> Send for MaxElapsedTime<P, C>
where P: Send, C: Send, <C as Clock>::Instant: Send,

§

impl<P, C> Sync for MaxElapsedTime<P, C>
where P: Sync, C: Sync, <C as Clock>::Instant: Sync,

§

impl<P, C> Unpin for MaxElapsedTime<P, C>
where P: Unpin, C: Unpin, <C as Clock>::Instant: Unpin,

§

impl<P, C> UnsafeUnpin for MaxElapsedTime<P, C>

§

impl<P, C> UnwindSafe for MaxElapsedTime<P, C>
where P: UnwindSafe, C: UnwindSafe, <C as Clock>::Instant: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P> PolicyExt for P
where P: BackoffPolicy,

Source§

fn max_attempts(self, max: u32) -> MaxAttempts<Self>

Cap the number of retries to max. See MaxAttempts. Read more
Source§

fn with_max_delay(self, max_delay: Duration) -> WithMaxDelay<Self>

Clamp every produced delay to at most max_delay. See WithMaxDelay.
Source§

fn max_elapsed_time<C: Clock>( self, clock: C, max_elapsed: Duration, ) -> MaxElapsedTime<Self, C>

Stop retrying after max_elapsed measured by clock. See MaxElapsedTime.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.