Skip to main content

TryAsync

Struct TryAsync 

Source
pub struct TryAsync<'a, E, F> { /* private fields */ }
Available on crate features async-io-2 or tokio only.
Expand description

.awaitable type returned by EaseOff::try_async() and EaseOff::try_async_with().

§Panics

If an async runtime is not available for sleeping between retries.

§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 Self::enforce_deadline_with().

Implementations§

Source§

impl<'a, T, E, F, Fut> TryAsync<'a, E, F>
where F: FnOnce() -> Fut, Fut: Future<Output = Result<T, E>>,

Source

pub async fn enforce_deadline_with( self, make_error: impl FnOnce(Option<E>) -> E, ) -> ResultWrapper<'a, T, E>

Cancel the operation as soon as the deadline elapses, if set.

The closure will be called to produce the error that will be returned; if the operation failed on a previous attempt, that error is included.

§Panics

If an async runtime is not available for managing the timeout.

§Example
use std::time::Duration;
use ease_off::EaseOff;

let mut ease_off = EaseOff::start_timeout(Duration::from_secs(5));

let result = ease_off
    // An async operation that will never complete.
    .try_async(std::future::pending::<Result<String, String>>())
    // You may either use the last error (`_e`) or create a new one
    .enforce_deadline_with(|_e: Option<String>| "deadline elapsed".to_string())
    .await
    .or_retry_if(|_e| false);

assert_eq!(result.unwrap_err(), "deadline elapsed");

Trait Implementations§

Source§

impl<'a, T, E, F, Fut> IntoFuture for TryAsync<'a, E, F>
where F: FnOnce() -> Fut, Fut: Future<Output = Result<T, E>>,

Source§

type Output = ResultWrapper<'a, T, E>

The output that the future will produce on completion.
Source§

type IntoFuture = TryAsyncFuture<'a, E, F, Fut>

Which kind of future are we turning this into?
Source§

fn into_future(self) -> Self::IntoFuture

Creates a future from a value. Read more

Auto Trait Implementations§

§

impl<'a, E, F> !UnwindSafe for TryAsync<'a, E, F>

§

impl<'a, E, F> Freeze for TryAsync<'a, E, F>
where F: Freeze,

§

impl<'a, E, F> RefUnwindSafe for TryAsync<'a, E, F>

§

impl<'a, E, F> Send for TryAsync<'a, E, F>
where F: Send, E: Send,

§

impl<'a, E, F> Sync for TryAsync<'a, E, F>
where F: Sync, E: Sync,

§

impl<'a, E, F> Unpin for TryAsync<'a, E, F>
where F: Unpin,

§

impl<'a, E, F> UnsafeUnpin for TryAsync<'a, E, F>
where F: UnsafeUnpin,

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