4 ms·
Is it true that async/await is syntactic sugar over Promises, and that Promises are sugar over callbacks? If that's true, does the "function coloring" problem
by endorphine 5y ago
Is it true that async/await is syntactic sugar over Promises, and that Promises are sugar over callbacks?
If that's true, does the "function coloring" problem apply to Promise-based code and callback-based code too? (Talking about JavaScript here)
- josephcsible 5y agoYes, function coloring applies to them too. The function coloring problem is semantic, not syntactic (with the possible exception of rule 4 "Red functions are more painful to call"), so no amount of adding or removing syntactic sugar will affect it.
- mattwad 5y agoPretty much... all you need to provide to `await` is an object with a 'thenable' function. Even this works: (async () => { const promise = { then (resolve) { resolve('World'); } }; console.log('Hello', await promise); })()