FutureExt

Trait FutureExt 

Source
pub trait FutureExt: Future {
    // Required methods
    fn join<S2>(self, other: S2) -> Join2<Self, <S2 as IntoFuture>::IntoFuture>
       where Self: Sized + Future,
             S2: IntoFuture;
    fn race<T, S2>(
        self,
        other: S2,
    ) -> Race2<T, Self, <S2 as IntoFuture>::IntoFuture>
       where Self: Sized + Future<Output = T>,
             S2: IntoFuture<Output = T>;

    // Provided method
    fn wait_until<D>(
        self,
        deadline: D,
    ) -> WaitUntil<Self, <D as IntoFuture>::IntoFuture> 
       where Self: Sized,
             D: IntoFuture { ... }
}
Available on crate feature nano-alloc only.
Expand description

An extension trait for the Future trait.

Required Methods§

Source

fn join<S2>(self, other: S2) -> Join2<Self, <S2 as IntoFuture>::IntoFuture>
where Self: Sized + Future, S2: IntoFuture,

Wait for both futures to complete.

Source

fn race<T, S2>( self, other: S2, ) -> Race2<T, Self, <S2 as IntoFuture>::IntoFuture>
where Self: Sized + Future<Output = T>, S2: IntoFuture<Output = T>,

Wait for the first future to complete.

Provided Methods§

Source

fn wait_until<D>( self, deadline: D, ) -> WaitUntil<Self, <D as IntoFuture>::IntoFuture>
where Self: Sized, D: IntoFuture,

Delay resolving the future until the given deadline.

The underlying future will not be polled until the deadline has expired. In addition to using a time source as a deadline, any future can be used as a deadline too. When used in combination with a multi-consumer channel, this method can be used to synchronize the start of multiple futures and streams.

§Example
use async_io::Timer;
use futures_concurrency::prelude::*;
use futures_lite::future::block_on;
use std::time::{Duration, Instant};

block_on(async {
    let now = Instant::now();
    let duration = Duration::from_millis(100);

    async { "meow" }
        .wait_until(Timer::after(duration))
        .await;

    assert!(now.elapsed() >= duration);
});

Implementors§

Source§

impl<F1> FutureExt for F1
where F1: Future,