2 ms·
> The idea of pretending async functions are still "functions" is kinda terrible This makes no sense to me. An async function is just syntactic sugar for a (no
by hn_throwaway_99 3y ago
> The idea of pretending async functions are still "functions" is kinda terrible
This makes no sense to me. An async function is just syntactic sugar for a (normal in every way) function that returns a promise.
- zbentley 3y agoNot 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.