Hacker News new | ask | show | jobs
by quarterto 4818 days ago

  Next time you're about to define a function with a callback argument, don't.
No, do. It's the prevailing style in Node.js and elsewhere, and so there exist tools to transform them (syntactically or otherwise) into more palpable styles:

https://github.com/0ctave/node-sync https://github.com/BYVoid/continuation https://github.com/JeffreyZhao/wind https://github.com/Sage/streamlinejs

2 comments

I already knew about node-sync, but continuation really brings something new. I'll check the source to understand what it does under the hood.
Also, the comparison on the project's README is informative (and lists additional options):

https://github.com/BYVoid/continuation#relevant-projects

I agree, I often will write promise wrappers for other people's stuff, but for the external surface of my module I have callbacks.

Also, callbacks ARE sometimes nicer than promises, etc... especially if you have CoffeeScript function syntax.