Skip to main content

EaseOff

Struct EaseOff 

Source
pub struct EaseOff<E> { /* private fields */ }
Expand description

Exponential backoff controller.

The constructors of this type use Options::DEFAULT.

Implementations§

Source§

impl<E> EaseOff<E>

Backoff support for async/await.

§Note: Behavior at Deadline

Unless otherwise stated, async operations are not cancelled at the deadline once they are in-progress.

More specifically, if the deadline elapses after an async operation has begun, i.e. the future returned by these methods is .awaited or polled, it will be allowed to run to completion.

To cancel an in-progress operation when the deadline elapses, use TryAsync::enforce_deadline_with().

Source

pub fn try_async<T, Fut>( &mut self, op: Fut, ) -> TryAsync<'_, E, impl FnOnce() -> Fut>
where Fut: Future<Output = Result<T, E>>,

Available on crate features async-io-2 or tokio only.

Attempt an async operation.

The operation is immediately cancelled without being polled if the deadline has already elapsed. Otherwise, it is run to completion.

See the note on this impl block for details.

Source

pub fn try_async_with<T, F, Fut>(&mut self, op: F) -> TryAsync<'_, E, F>
where F: FnOnce() -> Fut, Fut: Future<Output = Result<T, E>>,

Available on crate features async-io-2 or tokio only.

Attempt the async operation returned by the given closure.

This allows for some lazy computation that is not executed if the deadline has already elapsed.

The closure is not called if the deadline has elapsed by the time the returned Future is polled. If the deadline elapses after the operation has begun, it is allowed to run to completion.

See the note on this impl block for details.

Source§

impl<E> EaseOff<E>

Source

pub fn start_unlimited() -> Self

Source

pub fn start_timeout(timeout: Duration) -> Self

Source

pub fn start_timeout_opt(timeout: Option<Duration>) -> Self

Source

pub fn start_deadline(deadline: Instant) -> Self

Source

pub fn start_deadline_opt(deadline: Option<Instant>) -> Self

Source

pub fn started_at(&self) -> Instant

Returns the Instant when this instance was constructed.

Source

pub fn deadline(&self) -> Option<Instant>

Returns the deadline, if provided.

If constructed with a timeout, it is converted to a deadline on construction by adding the timeout to Self::started_at().

Source

pub fn num_attempts(&self) -> u32

Returns the number of attempts that have been made.

Saturates at u32::MAX.

Source§

impl<E> EaseOff<E>

Source

pub fn try_blocking<T>( &mut self, op: impl FnOnce() -> Result<T, E>, ) -> ResultWrapper<'_, T, E>

Attempt a blocking operation.

If the operation previously failed, sleeps for the prescribed backoff period using std::thread::sleep().

§Note: Behavior at Deadline

Most blocking operations cannot be cancelled once begun, so the deadline, if set, is only checked before attempting the operation.

Generally, the only kinds of blocking operations that support cancellation take an explicit timeout (such as setting a read timeout on a socket).

If you want a blocking operation to be cancelled immediately once the deadline elapses, consult the documentation for the API you are calling to see if timeouts are supported, and if so, how to configure them.

Trait Implementations§

Source§

impl<E: Debug> Debug for EaseOff<E>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<E> Freeze for EaseOff<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for EaseOff<E>
where E: RefUnwindSafe,

§

impl<E> Send for EaseOff<E>
where E: Send,

§

impl<E> Sync for EaseOff<E>
where E: Sync,

§

impl<E> Unpin for EaseOff<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for EaseOff<E>
where E: UnsafeUnpin,

§

impl<E> UnwindSafe for EaseOff<E>
where E: 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V