AI Instructor Live Labs Included

Async Rust with Tokio

Async Rust with Tokio — Future trait, spawning tasks, join/select, async channels, cancellation, async I/O, and the Stream trait.

Intermediate
22h 20m
15 Lessons
SMU-RUST-600

About This Course

Learn how Rust does asynchronous programming the poll-based Future model, the Tokio runtime, and the patterns real production systems use for high-concurrency I/O. You will understand why async Rust is different from async in other languages, when it beats threads, when it does not, and how to compose futures with join, select, timeouts, and cancellation. By the end of this course you will be able to write async functions and spawn Tokio tasks, pick the right async channel (mpsc, oneshot, broadcast, watch) for a given shape, build an async TCP server that handles many connections concurrently, apply timeouts and cancellation correctly, and reason about Pin, async traits, and the Stream trait well enough to read the ecosystem. Prerequisites: Courses 1-5 of the Programming with Rust skill path, especially the Send/Sync and channel content from Course 5. Follows the Rust 2024 edition on stable Rust 1.99 with Tokio 1.47.

Course Curriculum

15 Lessons
01
AI Lesson
AI Lesson

Why async Rust — the poll model and the Future trait

1h 0m

Async in Rust is different. You will learn the poll-based Future model that makes it zero-cost, the mental model that separates async from threads, and the rule of thumb for which workloads should go async and which should stay on threads. By the end of this lesson you will be able to describe the Future trait, explain what .await does, and pick the right concurrency model (threads or async) for a given workload.

02
Lab Exercise
Lab Exercise

Your first async function with Tokio - Lab Exercises

1h 30m 3 Exercises

Write your first async Rust program with Tokio. You will mark main async with the Tokio runtime, write async functions, await futures, and see firsthand how awaiting multiple futures sequentially differs from awaiting them concurrently. By the end of this lab you will be able to run an async program with the Tokio runtime, write async functions, and reason about sequential vs concurrent execution.

03
AI Lesson
AI Lesson

The Tokio runtime and tokio::spawn

1h 0m

Tokio is not magic — it is a work-stealing executor you can see the shape of. You will learn the two runtime flavors (multi-thread and current-thread), how tokio::spawn creates a task that the runtime schedules, how tasks differ from threads in cost and semantics, and when to prefer each. By the end of this lesson you will be able to choose the right runtime flavor for your workload, spawn tasks from async code, and reason about where each task actually runs.

04
Lab Exercise
Lab Exercise

Spawning tasks and shared state - Lab Exercises

1h 45m 3 Exercises

Spawn multiple Tokio tasks, aggregate their results, and share state across them safely. You will discover why async code uses tokio::sync::Mutex instead of std::sync::Mutex, learn when to await a lock vs block on it, and build the muscle for structuring concurrent async work. By the end of this lab you will be able to spawn tasks, collect their results with JoinHandle, and share mutable state across tasks with Arc<tokio::sync::Mutex<T>>.

05
AI Lesson
AI Lesson

Awaiting multiple futures — join! and select!

1h 0m

Composing futures is where async pays off. You will learn join! for "wait for all", try_join! for "wait for all, fail fast", and select! for "whichever completes first" — and the cancellation-safety rules every production codebase lives by. By the end of this lesson you will be able to pick the right composition macro for a given shape and explain what happens to the losing branches of a select!.

06
Lab Exercise
Lab Exercise

Concurrent downloads with join! and select! - Lab Exercises

1h 45m 3 Exercises

Fetch many things at once with Tokio. You will fetch a list of resources concurrently with join!, grab whichever finishes first with select!, and insist that every fetch succeed with try_join!. By the end of this lab you will be able to reach for the right composition macro the moment the shape of the problem comes into view.

07
AI Lesson
AI Lesson

Async channels — mpsc, oneshot, broadcast, watch

1h 15m

Tokio ships four channel shapes because real systems need them all. You will learn mpsc for pipelines, oneshot for request/response, broadcast for fan-out, and watch for latest-value state. By the end of this lesson you will be able to pick the right channel for any communication shape you encounter and explain the backpressure, closure, and lag semantics of each.

08
Lab Exercise
Lab Exercise

Build a chat room with broadcast channels - Lab Exercises

2h 0m 3 Exercises

Fan-out in action. You will build a chat room where many subscribers receive every message, each connection runs in its own task, and dropped receivers are cleaned up gracefully. By the end of this lab you will be able to use tokio::sync::broadcast for fan-out, structure per-connection tasks, and handle receiver lag and disconnect without crashing.

09
AI Lesson
AI Lesson

Async I/O — AsyncRead, AsyncWrite, buffered streams

1h 0m

Async I/O is where Rust's zero-cost promise really shows. You will learn the AsyncRead and AsyncWrite traits that mirror their synchronous siblings, when to wrap a stream in a buffered reader, and how to frame lines without hand-rolling a parser. By the end of this lesson you will be able to read and write to async sockets, buffer efficiently, and reach for Framed when a protocol gets complicated.

10
Lab Exercise
Lab Exercise

Build a TCP line-echo server - Lab Exercises

1h 45m 3 Exercises

A production-shaped TCP server in a hundred lines. You will accept many concurrent connections, echo each line back, structure the per-connection task cleanly, and verify the whole thing from an integration test on an ephemeral port. By the end of this lab you will be able to build a Tokio TCP server that handles many connections concurrently and test it reliably.

11
AI Lesson
AI Lesson

Cancellation, timeouts, and CancellationToken

1h 0m

The hardest async bug is the work that keeps running after you asked it to stop. You will learn tokio::time::timeout, cooperative cancellation at .await points, the CancellationToken pattern from tokio-util, and graceful shutdown through a watch channel. By the end of this lesson you will be able to cap any async operation with a timeout, propagate cancellation through a task tree, and shut down a service without stranding work.

12
Lab Exercise
Lab Exercise

Robust HTTP client with timeout and cancellation - Lab Exercises

1h 45m 3 Exercises

Build the HTTP client every production system eventually needs. You will apply per-request timeouts, propagate cancellation through a tree of in-flight calls, and bound total work with a semaphore. By the end of this lab you will be able to cap any async request with a timeout and cancel in-flight work cleanly from a parent task.

13
AI Lesson
AI Lesson

Pin, async traits, and the Stream trait

1h 15m

Three advanced ideas you will meet in every mature async codebase. You will learn why futures must be pinned, how Rust 2024's native async fn in traits works, and the Stream trait that models an async sequence of values. By the end of this lesson you will be able to read Pin<Box<dyn Future>> without flinching, write async traits, and consume an async stream with StreamExt combinators.

14
Lab Exercise
Lab Exercise

Build a custom Stream combinator - Lab Exercises

1h 45m 3 Exercises

Implement Stream by hand to make the trait concrete. You will build a tick generator that emits a value every N milliseconds, chain it through StreamExt combinators, and understand Pin from the inside. By the end of this lab you will be able to implement a Stream, compose streams with map/take/chain, and reason about Pin well enough to debug async-trait signatures.

15
Lab Exercise
Lab Exercise

Capstone — async telemetry server - Lab Exercises

2h 35m 5 Exercises

Ship a real async service. You will build a TCP telemetry server that accepts many clients, broadcasts each client's input to all other clients, keeps per-connection state, counts throughput with an atomic, and shuts down cleanly on Ctrl-C. By the end of this capstone you will have wired together Tokio tasks, broadcast channels, per-connection state, cancellation, and metrics into one coherent async service.

This course includes:

  • 24/7 AI Instructor Support
  • Live Lab Environments
  • 8 Hands-on Lessons
Skill Level Intermediate
Total Duration 22h 20m