async_timer

Enum Timed

Source
pub enum Timed<F, T = Timer> {
    // some variants omitted
}
Expand description

Limiter on time to wait for underlying Future

§Usage

async fn job() {
}

async fn do_job() {
    let work = unsafe {
        async_timer::Timed::platform_new_unchecked(job(), core::time::Duration::from_secs(1))
    };

    match work.await {
        Ok(_) => println!("I'm done!"),
        //You can retry by polling `expired`
        Err(expired) => println!("Job expired: {}", expired),
    }
}

Implementations§

Source§

impl<F: Future + Unpin> Timed<F>

Source

pub fn platform_new(inner: F, timeout: Duration) -> Self

Creates new instance using Timer alias.

Source§

impl<F: Future> Timed<F>

Source

pub unsafe fn platform_new_unchecked(inner: F, timeout: Duration) -> Self

Creates new instance using Timer alias.

Unsafe version of platform_new that doesn’t require Unpin.

Source§

impl<F: Future + Unpin, T: Oneshot> Timed<F, T>

Source

pub fn new(inner: F, timeout: Duration) -> Self

Creates new instance with specified timeout

Requires to specify Oneshot type (e.g. Timed::<oneshoot::Timer>::new())

Source§

impl<F: Future, T: Oneshot> Timed<F, T>

Source

pub unsafe fn new_unchecked(inner: F, timeout: Duration) -> Self

Creates new instance with specified timeout

Unsafe version of new that doesn’t require Unpin.

Requires to specify Oneshot type (e.g. Timed::<oneshoot::Timer>::new())

Trait Implementations§

Source§

impl<F: Future, T: Oneshot> Future for Timed<F, T>

Source§

type Output = Result<<F as Future>::Output, Expired<F, T>>

The type of value produced on completion.
Source§

fn poll(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Self::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more
Source§

impl<F: Future + Unpin, T: Oneshot> Unpin for Timed<F, T>

Auto Trait Implementations§

§

impl<F, T> Freeze for Timed<F, T>
where T: Freeze, F: Freeze,

§

impl<F, T> RefUnwindSafe for Timed<F, T>

§

impl<F, T> Send for Timed<F, T>
where T: Send, F: Send,

§

impl<F, T> Sync for Timed<F, T>
where T: Sync, F: Sync,

§

impl<F, T> UnwindSafe for Timed<F, T>
where T: UnwindSafe, F: 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> 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<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

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

type IntoFuture = F

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

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. 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.