expression

join!: collect all branch results

Run independent futures concurrently inside one task, collecting results in argument order. This does not guarantee parallel CPU execution. A blocking branch prevents the current task from polling others. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 4 6 Common mistake: Treating join! as a thread pool or assuming results follow completion order.

Formal Syntax & Structure

rust syntaxrust
let (a, b) = tokio::join!(future_a, future_b);

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread", start_paused = true)]async fn main() {    use tokio::time::{sleep, Duration};    let (a, b) = tokio::join!(async { sleep(Duration::from_secs(2)).await; 4 }, async { 6 });    println!("{a} {b}");}
Rust Reference