← Lessons

quiz vs the machine

Gold1400

Concurrency

The Async Runtime Executor

The engine that drives futures forward by polling them until they complete.

5 min read · core · beat Gold to climb

The piece that runs your futures

An async function does nothing on its own. It produces a future, a value that represents work not yet finished. The executor is the runtime component that takes futures and drives them to completion.

How polling works

The executor calls poll on a future. The future runs until it either finishes or hits an await it cannot satisfy yet.

  • If the future returns Ready, its result is available and the executor is done with it.
  • If it returns Pending, the future has parked itself and the executor moves on to other work.

The executor keeps a ready queue of tasks that can make progress. It pulls one, polls it, and either completes it or sets it aside until it becomes ready again.

Why it does not busy loop

A naive runtime would poll pending futures over and over, burning CPU. A real executor only re polls a task when it is told the task can progress, which is the job of the waker covered separately. Until then the task sleeps and the core is free.

Key idea

The executor drives futures by polling tasks from a ready queue, completing the ones that return Ready and parking those that return Pending so the core stays free.

Check yourself

Answer to earn rating on the learn ladder.

1. What does poll returning Pending mean?

2. Why does a good executor avoid re polling pending tasks constantly?

3. What does the executor keep tasks in while they are runnable?