Function poll_immediate

fn poll_immediate<F: Future>(f: F) -> PollImmediate<F>

Creates a future that is immediately ready with an Option of a value. Specifically this means that poll always returns Poll::Ready.

Caution

When consuming the future by this function, note the following:

Examples

# futures::executor::block_on(async {
use futures::future;

let r = future::poll_immediate(async { 1_u32 });
assert_eq!(r.await, Some(1));

let p = future::poll_immediate(future::pending::<i32>());
assert_eq!(p.await, None);
# });

Reusing a future

# futures::executor::block_on(async {
use futures::{future, pin_mut};
let f = async {futures::pending!(); 42_u8};
pin_mut!(f);
assert_eq!(None, future::poll_immediate(&mut f).await);
assert_eq!(42, f.await);
# });