Skip to content

What's the proper way to spawn a task on current thread? #3947

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

You must be logged in to vote

If all you are using is the LocalSet::run_until method, you should consider simply using tokio::join!. Both halves of a tokio::join! are part of the same task, so they will be executed together on the same thread.

If you do want to use a LocalSet, then you should probably be spawning both tasks on the LocalSet with its spawn_local method. You can then .await the LocalSet which completes once all tasks spawned on the set return.

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@RealXuChe
Comment options

@brandonros
Comment options

@Darksonn
Comment options

@brandonros
Comment options

@Darksonn
Comment options

Answer selected by RealXuChe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants