Re:Sane Async Patterns in JavaScript
by IgorPartola on Thursday April 04, 2013 @05:39PM
(#5495474)
It's easy to see what's happening if everything is written in one file. It's hard if your callback are fired from and/or go into minimized library code you don't control or don't want to debug. You may have your own pyramid, but it's really sitting on someone else's pyramid.
Yeah, the real problem for me with the nested case is error handling. It's all manual, and the default (unless you're very careful) is that errors do not propagate and will instead simply be lost and ignored.
The fact that the pyramid makes it easy to see the sequence, i.e. follow the chain of causation, and easy to find the callbacks, argues that there is a place for it. Additionally, it makes it easy to transfer state through the chain, since each callback has access to the previous one's variables.
The other patterns, which probably all have appropriate uses, too, would seem to carry a greater risk of spaghetti -- i.e. control that jumps around unexpectedly and is hard to follow.