Skip to content

Add Futures to a join! while it is being polled #4692

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

You must be logged in to vote

The JoinSet type works by spawning actual tasks, so if you are using a multi-threaded runtime, this means that the tasks can end up on different threads. One option you could go for is the FuturesUnordered utility, which can let you run them inside a single task, however running many things inside a single task is somewhat inefficient. It's better to spawn them as separate tasks.

I recommend that you use a single-threaded runtime and use tokio::spawn (or a JoinSet) to spawn them.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@edgarogh
Comment options

Answer selected by edgarogh
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