this post was submitted on 19 Oct 2024
36 points (95.0% liked)
Rust
5930 readers
32 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
Maybe this is a reductionist simplification of it, but his point is basically that, at least in the context of rust, async code is explicit and easy to introduce in a blocking context by simply blocking on it, while blocking code is not explicit about how blocky it is (and it's not a binary), and thus, it's not trivial to know where explicit unblocks are needed in an async context.
Blocking on async code is usually done with
some_executor::block_on()
, of which some very lightweight implementations exist, combined with the possibility of not requiring that the data's ownership be moved to the executor, nor is the data required to beSend
able to other threads (an executor doesn't have to be a multi-threaded work-stealing one).Meanwhile, unblocking is done usually via
blocking::unblock()
orsome_executor::spawn_blocking()
, and doesn't offer such flexibility.