-
I want to create a task in the current thread because I don't want to take the synchronization overhead. I tried the following code but ran into problems : LocalSet::new().run_until(async move {
some code // It seems that until it returns.......
}).await;
more code // Code here will not be executed? The task started with spawn(async move {
some code // This.....
});
other code // .....and this will be executed simultaneously. What's the proper way to spawn a task on current thread? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
If all you are using is the If you do want to use a |
Beta Was this translation helpful? Give feedback.
If all you are using is the
LocalSet::run_until
method, you should consider simply usingtokio::join!
. Both halves of atokio::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 theLocalSet
with itsspawn_local
method. You can then.await
theLocalSet
which completes once all tasks spawned on the set return.