pub fn poll_immediate<F>(f: F) -> PollImmediate<F> where
    F: Future,
Expand description

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:

  • This function does not guarantee that the future will run to completion, so it is generally incompatible with passing the non-cancellation-safe future by value.
  • Even if the future is cancellation-safe, creating and dropping new futures frequently may lead to performance problems.

Examples

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

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);