4 ms·
Not necessarily. That's (mostly) true in e.g. JavaScript, but is not true in Rust. My novice understanding of the Rust model is that an async function is compi
by zbentley 3y ago
Not necessarily. That's (mostly) true in e.g. JavaScript, but is not true in Rust.
My novice understanding of the Rust model is that an async function is compiled down to a state machine and a set of functions which execute parts of the async function's code and then manipulate the state machine. Those manipulations have two broad categories of side effects: they can wake up/be observed by pollers, and can change the state of later parts of the task corresponding to an invocation of the original async fn (e.g. by setting variables for subsequent functions in the set--code on the other side of an internal await point that uses the result of the await).
In other words, async functions in some languages are more than just sugar for "delegate to event loop and return promise resolved by delegate completion".
- withoutboats3 3y agoI don’t really understand what you mean about side effects but async functions do indeed just return futures just like JavaScript async functions return promises - rust futures just are compiled into state machines in a way JavaScript promises are not.