top | item 16514428

Node.js callbacks vs. promises vs. generators vs. async-await

32 points| wheresvic1 | 8 years ago |smalldata.tech

12 comments

order
[+] semireg|8 years ago|reply
Thank you for the date references. I just finished reading a book on Node/SailsJS and this is a great summary and overview. I’m an app developer by day but spend a lot of time keeping current on other technologies.
[+] andrewmcwatters|8 years ago|reply
and yet the only portable style here is callbacks
[+] aussieguy123|8 years ago|reply
You can use a transpiler like babel if you want to run async await etc on platforms that don't support them yet
[+] fancyfacebook|8 years ago|reply
About two years ago I opened up a smallish JS file (~100 lines ) and it contained 47 promises, some on the same line.

That was the day I decided JS had gotten way too far up it's own ass and abandoned my career in web development. Every day that goes by makes it seem like a better and better decision.

[+] HyperMassive|8 years ago|reply
> That was the day I decided JS...

Why? surely having 47 promises and some on the same line is the authors fault?

Promise.prototype.then()'s callback function does not need to be written inline. At some point the author should have realised it hass become difficult to grok quickly and refactored them out using appropriate function names.

[+] SamReidHughes|8 years ago|reply
If you're doing I/O in an event loop it's either 47 promises or 47 callbacks.
[+] wheresvic1|8 years ago|reply
> About two years ago I opened up a smallish JS file (~100 lines ) and it contained 47 promises, some on the same line.

This is exactly what async await is trying to simplify :)

[+] gitgud|8 years ago|reply
Is there an actual reference for this? Sounds like it was minified or just bad coding style. Which can happen in any language.
[+] ziikutv|8 years ago|reply
Here's hoping it gets even better in future so they can win us both back ;)

---

Great article OP. Thank you very much. I remember using Bluebird and sharing the sentiments of the comment which I am replying to.