expression

Await: compose an asynchronous result

Await delegates progress to its operand and evaluates to the output once available. It can suspend the enclosing computation when the operand is unfinished, but need not suspend when the value is immediately available. Await does not spawn another task by itself. Expected stdout (not executed): Ready(12) Common mistake: Assuming two consecutive awaits automatically execute concurrently.

Formal Syntax & Structure

rust syntaxrust
let result = future.await;

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);    async fn price() -> u32 { 4 }    async fn count() -> u32 { 3 }    let mut f = std::pin::pin!(async { price().await * count().await });    println!("{:?}", f.as_mut().poll(&mut cx));}
Rust Reference