expression
JoinSet: supervise a group of tasks
Collect tasks with a shared output type and observe results as tasks finish. Completion order is not submission order. A group can provide an explicit ownership boundary for tasks; limit group size separately. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): [2, 4, 6] Common mistake: Asserting completion order or treating JoinSet as an automatic concurrency limit.
Formal Syntax & Structure
rust syntaxrust
JoinSet::new(); set.spawn(future); set.join_next().awaitWorking Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { let mut group = tokio::task::JoinSet::new(); for n in [3u32, 1, 2] { group.spawn(async move { n * 2 }); } let mut results = Vec::new(); while let Some(result) = group.join_next().await { results.push(result.unwrap()); } results.sort_unstable(); println!("{results:?}");}