3 ms·
JavaScript Promises from the Ground Up
- moritzwarhier 2y agoVery well-written and easy to follow, wish I had read this a couple years ago :) I would love a follow-up that fills the gap about the relatio ship between generator functions and promises though. This part seems very transparent in practise, but I think they're also the reason why the article gets slightly fuzzy at the end. It claims that 99% of developers need not to care about promise "unwrapping". But isn't that what powers every async function with more than one "await" in it? Would also love to read a thorough breakdown of immediately resolved promises and their duality with setTimeout(resolve, 0).
- gabrielsroka 2y agoSee my comment above and also https://news.ycombinator.com/item?id=40825220 https://news.ycombinator.com/item?id=40825220 And https://news.ycombinator.com/item?id=40240905 https://news.ycombinator.com/item?id=40240905
- etse 2y agoAgreed. This is very well written. I discovered the joy of Go from dealing with JavaScript promises while writing an API service in Node. So many painful runtime errors uncaught or unlogged because promises don’t (or didn’t) require the catch callback. I think inverting the programming perspective to default to sync instead of async is more productive for web services development, than perhaps for UI.
- gabrielsroka 2y ago> the await keyword is syntactic sugar for the .then() callback: async/await is not just syntactic sugar. See https://news.ycombinator.com/item?id=23701736 https://news.ycombinator.com/item?id=23701736 And the rest of thread
- rauschma 2y agoIt depends on what you mean by syntactic sugar. I follow this definition: https://en.wikipedia.org/wiki/Syntactic_sugar https://en.wikipedia.org/wiki/Syntactic_sugar You can indeed translate an async function to an equivalent function that uses .then() but it’s a radical change, not syntactic sugar (as I use that term).