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

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


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.


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};
assert_eq!(None, future::poll_immediate(&mut f).await);
assert_eq!(42, f.await);