futures_lite::future

Trait FutureExt

Source
pub trait FutureExt: Future {
    // Provided methods
    fn poll(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output>
       where Self: Unpin { ... }
    fn or<F>(self, other: F) -> Or<Self, F> 
       where Self: Sized,
             F: Future<Output = Self::Output> { ... }
}
Expand description

Extension trait for Future.

Provided Methods§

Source

fn poll(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output>
where Self: Unpin,

A convenience for calling Future::poll() on !Unpin types.

Source

fn or<F>(self, other: F) -> Or<Self, F>
where Self: Sized, F: Future<Output = Self::Output>,

Returns the result of self or other future, preferring self if both are ready.

If you need to treat the two futures fairly without a preference for either, use the [race()] function or the [FutureExt::race()] method.

§Examples
use futures_lite::future::{pending, ready, FutureExt};

assert_eq!(ready(1).or(pending()).await, 1);
assert_eq!(pending().or(ready(2)).await, 2);

// The first future wins.
assert_eq!(ready(1).or(ready(2)).await, 1);

Implementors§

Source§

impl<F: Future + ?Sized> FutureExt for F