Skip to content

tokio::join vs tokio::task::JoinSet #6921

Closed Answered by Darksonn
joelchen asked this question in Q&A
Discussion options

You must be logged in to vote

It doesn't make any sense to use tokio::join! in that example. It's just a complicated, slower way to write this:

let t1_handler = tokio::spawn(t1());
let t2_handler = tokio::spawn(t2());
let res1 = t1_handler.await;
let res2 = t2_handler.await;

This will be faster than JoinSet. The time when you should use JoinSet is when you need to act on tasks exiting immediately. If you're just waiting for all of them to exit, there's no real advantage over using JoinHandle directly.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by joelchen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants