[][src]Macro smol::ready

macro_rules! ready {
    ($e:expr $(,)?) => { ... };
}

Unwraps Poll<T> or returns Pending.

Examples

use futures_lite::future::FutureExt;
use futures_lite::ready;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

// Polls two futures and sums their results.
fn poll_sum(
    cx: &mut Context<'_>,
    a: Pin<&mut impl Future<Output = i32>>,
    b: Pin<&mut impl Future<Output = i32>>,
) -> Poll<i32> {
    let x = ready!(a.poll(cx));
    let y = ready!(b.poll(cx));
    Poll::Ready(x + y)
}