Book 1 · Lesson 1.11

Rust async and Tokio

  • Contrast JS microtasks with Rust async tasks
  • Trace a webhook handler through yield points
  • Identify .await as cooperative scheduling

Prerequisites: 1.10

Lesson 1.3 previewed this — now we go deep.

One thread, many tasks

Tokio multiplexes thousands of async tasks on a small thread pool. When code hits .await, the task yields so other webhooks can run.

TokioFutureMachine walks: idle → poll → await Kafka → resume → HTTP response.

Not the browser event loop

Browser JSRust Tokio
SchedulerSingle thread + microtasksThread pool + cooperative tasks
BlockingBlocks the tabspawn_blocking for CPU/sync I/O
ExampleTanStack refetchingestion Kafka publish

Read the real handler

Open services/ingestion/src/main.rs — find github_webhook and mark every .await.

Teach-back prompt

What happens to other requests while one handler awaits Kafka?

Trace one handler

Lesson 1.11 check

1. .await in Tokio…