Re:Fixing the callback spaghetti in node.js
by gfxmonk on Thursday September 29, 2011 @01:51AM
(#3051294)
got a link? I'd be interested to know how it deals with errors / exceptions, for example.
[ Parent
| on HN ]
Re:Fixing the callback spaghetti in node.js
by snprbob86 on Thursday September 29, 2011 @04:07AM
(#3051584)
I've been using: https://github.com/caolan/async
It looks pretty decent in CoffeeScript:
blah = (done) ->
async.series [
(next) -> foo next
(next) => @bar.baz 1, 2, 3, next
(next) ->
x = y
z w next
], done
Re:Fixing the callback spaghetti in node.js
by gfxmonk on Thursday September 29, 2011 @03:18AM
(#3051485)
Looks concise, but doesn't much help with the fundamental problems of callback code - exceptions don't work right, and "callbacks all the way down" whenever something starts having any async computation.
Re:Fixing the callback spaghetti in node.js
by weixiyen on Thursday September 29, 2011 @04:19AM
(#3051603)
what do you mean by this -> "callbacks all the way down" whenever something starts having any async computation.
Re:Fixing the callback spaghetti in node.js
by gfxmonk on Thursday September 29, 2011 @08:56AM
(#3052241)
Imagine function a calls b() and function b calls c(), and they're all sync.
Now, let's say c() changes and needs to call someAsyncFunction() and provide a callback. Which means c itself needs to take a callback. Which means b needs to provide a callback, so b needs to also take a callback, so a needs to provide a callback. And so forth.
Callbacks are infectious - once anybody in the call stack needs one, everybody needs one even if they just pass it on down the stack. Unless you don't need to do anything with return values, but that's fairly rare.