34
Blocking code is a leaky abstraction – notgull
(notgull.net)
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Credits
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.