liveBook · Manning

Join!

As explained in Rust Servers, Services, and Apps

The Rust join macro drives multiple asynchronous computations and completes after all of them complete.

The Rust join! macro waits for multiple asynchronous computations and completes only after every supplied task has completed. With Tokio, it is used inside an async main function to coordinate concurrently scheduled work. section 10.2

Joining two file reads

An async main function spawns two Tokio tasks for simulated file reads, then evaluates tokio::join!(h1, h2). Each task must await its asynchronous read; without .await, the lazy functions do not execute. The sample output shows file 2 completing before file 1, while join! waits for both. section 10.2

How Rust Servers, Services, and Apps covers it

How deep it goes
Explains completion, lazy async functions, awaiting, spawning, and scheduling, but does not develop macro internals.
Examples
Uses two simulated file-reading tasks whose four-second and two-second delays produce observable completion ordering.
What it assumes
Assumes familiarity with functions and threads, while introducing async functions, await, Tokio, and asynchronous task scheduling.
What you can do after
Apply it via Tokio to wait for multiple spawned asynchronous operations in an async main function.
How it connects
Connects async functions, await, Tokio runtime, asynchronous tasks, and task spawning.

Also explained in

Compare how 2 books explain join! →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.