Trait wasm_timer::TryFutureExt[][src]

pub trait TryFutureExt: TryFuture + Sized {
    fn timeout(self, dur: Duration) -> Timeout<Self>

Notable traits for Timeout<F>

impl<F> Future for Timeout<F> where
    F: TryFuture,
    F::Error: From<Error>, 
type Output = Result<F::Ok, F::Error>;

    where
        Self::Error: From<Error>
, { ... }
fn timeout_at(self, at: Instant) -> Timeout<Self>

Notable traits for Timeout<F>

impl<F> Future for Timeout<F> where
    F: TryFuture,
    F::Error: From<Error>, 
type Output = Result<F::Ok, F::Error>;

    where
        Self::Error: From<Error>
, { ... } }

An extension trait for futures which provides convenient accessors for timing out execution and such.

Provided methods

fn timeout(self, dur: Duration) -> Timeout<Self>

Notable traits for Timeout<F>

impl<F> Future for Timeout<F> where
    F: TryFuture,
    F::Error: From<Error>, 
type Output = Result<F::Ok, F::Error>;
where
    Self::Error: From<Error>, 
[src]

Creates a new future which will take at most dur time to resolve from the point at which this method is called.

This combinator creates a new future which wraps the receiving future in a timeout. The future returned will resolve in at most dur time specified (relative to when this function is called).

If the future completes before dur elapses then the future will resolve with that item. Otherwise the future will resolve to an error once dur has elapsed.

Examples

use std::time::Duration;
use futures::prelude::*;
use wasm_timer::TryFutureExt;

fn main() {
    let future = long_future();
    let timed_out = future.timeout(Duration::from_secs(1));

    async_std::task::block_on(async {
        match timed_out.await {
            Ok(item) => println!("got {:?} within enough time!", item),
            Err(_) => println!("took too long to produce the item"),
        }
    })
}

fn timeout_at(self, at: Instant) -> Timeout<Self>

Notable traits for Timeout<F>

impl<F> Future for Timeout<F> where
    F: TryFuture,
    F::Error: From<Error>, 
type Output = Result<F::Ok, F::Error>;
where
    Self::Error: From<Error>, 
[src]

Creates a new future which will resolve no later than at specified.

This method is otherwise equivalent to the timeout method except that it tweaks the moment at when the timeout elapsed to being specified with an absolute value rather than a relative one. For more documentation see the timeout method.

Loading content...

Implementors

impl<F: TryFuture> TryFutureExt for F[src]

Loading content...