Re:Internals of Async / Await in JavaScript
by heavenlyblue on Saturday September 02, 2023 @05:58AM
(#37360041)
You could also have an object with on_success, on_failure attributes so Futures are the same syntax sugar
Re:Internals of Async / Await in JavaScript
by littlestymaar on Saturday September 02, 2023 @10:15AM
(#37361724)
In JavaScript, where you have first class functions and an event loop built-in, yes. But for languages that lack one of those, then no.
Re:Internals of Async / Await in JavaScript
by btown on Saturday September 02, 2023 @06:31AM
(#37360199)
IMO this is like saying a high-level language is syntactic sugar for assembly.
Generators allow you to write a state machine as a procedural function whose local variables are automatically suspended when you yield and restored when the caller returns control to the generator. They compile this down to, as you said, an object with a call method. But that transformation is as nontrivial as any compilation/transpilation project.
Some patterns become easier to write with the generator syntax, but it's not really adding expressive power. (Unlike futures for instance)