Async Rust · 19 min · free with an account

Futures

Lesson preview · about 30%

An async function returns a future that has not run yet.

Core idea

Futures are lazy: no poll, no progress.

Start with the idea

Calling an async fn does nothing on its own: it builds a state machine that makes progress only when polled. .await yields at that point, letting the executor run something else while the operation is pending — which is how one thread can service thousands of waits.

Calling an async fn creates a future that represents work to be performed. It does not run the body to completion immediately. An executor polls the future; it may return Poll::Pending, register a way to be woken, and yield the thread to other tasks. When the awaited operation can make progress, the waker schedules another poll. Eventually the future returns Poll::Ready(value). This is why many I/O waits can share a small number of threads.

An .await marks a point where the task may suspend.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Concurrency & Async