std-module

std::task: polling and wake notifications

Task primitives let a caller pass notification information and inspect the state of a computation. A runtime combines these with scheduling and event sources. A no-op Waker here is suitable only for a future known to complete immediately. Expected stdout (not executed): true Common mistake: Treating a wake notification as the result of the future.

Formal Syntax & Structure

rust syntaxrust
use std::task::{Poll, Context, Waker};

Working Example

Example Snippetrust
fn main() {    use std::{future::Future, task::{Context, Poll, Wake, Waker}, sync::Arc};    struct Noop;    impl Wake for Noop { fn wake(self: Arc<Self>) {} }    let w = Waker::from(Arc::new(Noop));    let mut cx = Context::from_waker(&w);    let mut f = std::pin::pin!(async { 3 * 4 });    println!("{}", matches!(f.as_mut().poll(&mut cx), Poll::Ready(12)));}
Rust Reference