this post was submitted on 05 Sep 2024
58 points (100.0% liked)
Rust
5960 readers
8 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I skimmed the latter parts of this post since I felt like I read it all before, but I think
moro
is new to me. I was intrigued to find out how scopedspan
exactly behaves.This prints:
So scoped
spawn
doesn't really spawn tasks as one might mistakenly think!I think I would put the emphasis slightly differently: I don’t feel the confusion is around the word “spawn”, but it spawns futures rather than tasks. For tasks you might indeed expect them to be picked up in the background (which is what work-stealing does), but futures only execute when polled.
The most interesting part here is the polling only has to take place on the scope itself. That was actually what I wanted to check, but got distracted because all spawns are awaited in the scope in
moro
's README example.The non-awaited jobs are run concurrently as the moro docs say. But what if we immediately await f2?
f1 and f2 are run concurrently, f3 is run after f2 finishes, but doesn't have to wait for f1 to finish, which is maybe obvious, but... (see below).
So two things here:
defer_to_scope()
be confusing if the job is awaited in the scope?