3 ms·
No it's not. async/await's semantic is similar to coroutines, and is implemented by them.
by h8hawk 7y ago
No it's not. async/await's semantic is similar to coroutines, and is implemented by them.
- ihuman 7y agoAre you sure? From what I can find, async [0] causes a function to a return a promise, which then returns the result. Await [1] takes a promise, and waits for it to either be resolved or rejected. [0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- matt-attack 7y ago> and waits for it Yes but that doesn’t mean other lines of code can’t be executing while waiting. The waiting isn’t truly blocking the entire application. Plenty of other things can be happening.
- deleted 7y ago[deleted]
- nemetroid 7y agoSure, but the next line of the function awaiting the result can't execute while waiting.
- h8hawk 7y agofrom your first link: "... , async/await is similar to combining generators and promises."
- gitgud 7y agoMaybe provide some evidence of this, I've also understood them as syntactic sugar for Promises. Although I have found that babel does seem to transpile them differently to Promises
- s_tec 7y agoIt 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.