What is tokio task JoinSet

A JoinSet manages multiple async tasks and yields results as they complete.

A tokio::task::JoinSet is a collection that manages multiple spawned async tasks and allows you to wait for them to complete in the order they finish.

use tokio::task::JoinSet;

let mut set = JoinSet::new();

for i in 0..10 {
    set.spawn(async move { i * 2 });
}

while let Some(result) = set.join_next().await {
    println!("Task finished: {:?}", result);
}