3 ms·
It is true that async functions work similarly to the coroutines found in other languages, and that some transpilers convert async functions into Javascript gen
by s_tec 7y ago
It is true that async functions work similarly to the coroutines found in other languages, and that some transpilers convert async functions into Javascript generator functions under the hood. However, these are both implementation details.
On the flip side, there is a Javascript transpiler called nodent which directly converts async functions into the corresponding `Promise.then` calls, with no generators in sight. This transpiler actually generates smaller & faster output than the standard generator-based approaches, since the async/await semantics map more directly to promises.
In other words, async functions really are semantic sugar for promises, even if they have some similarities to coroutines / generators.
To try it yourself, just go to http://nodent.mailed.me.uk/ http://nodent.mailed.me.uk/ , check the "spec compliant" option, and look at the generated output.