rama-core 0.3.0

rama service core code, used by rama and service authors
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! `core::future` extension

use core::task::{Context, Poll};

/// Poll the future once and return `Some` if it is ready, else `None`.
///
/// If the future wasn't ready, it future likely can't be driven to completion any more: the polling
/// uses a no-op waker, so knowledge of what the pending future was waiting for is lost.
pub fn now_or_never<F: Future>(fut: F) -> Option<F::Output> {
    let waker = core::task::Waker::noop();
    let mut cx = Context::from_waker(waker);
    let fut = core::pin::pin!(fut);
    match fut.poll(&mut cx) {
        Poll::Ready(res) => Some(res),
        Poll::Pending => None,
    }
}