-
What are the differences between using the join macro and using JoinSet for running multiple asynchronous tasks concurrently and waiting for them to finish? Do they have the same performance?
Similar issue found but it is not using the join macro, instead using JoinHandle returned from tokio::spawn pushed into FuturesUnordered: #5564 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It doesn't make any sense to use 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 |
Beta Was this translation helpful? Give feedback.
It doesn't make any sense to use
tokio::join!
in that example. It's just a complicated, slower way to write this:This will be faster than
JoinSet
. The time when you should useJoinSet
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 usingJoinHandle
directly.