While this is a good article, things like this make me wonder if Node's asynchronous programming model is a good one. Certainly I don't think it's worth the mental overhead when you aren't dealing with highly concurrent IO situtations.<p>I constantly feel like I have to jump through hoops when programming against async APIs. None of the code in the article feels "elegant" to me.<p>Of course the popular alternative, preemptive multithreading with shared mutable state, is probably worse.
Im curious on node fibers. They seem like a second class citizen in node, any chance they will become mainstream or will it always be like Twisted is to Python.
This arrived just in time since I deployed my first Node app on Joyent last night! Great examples--they're all pretty new to me, but I'm planning to revisit your tips when I get further along.
I'm experiencing "node anxiety", let me explain:<p>There really are two kinds of functions in a node program.<p>Synchronous functions and asynchronous functions.<p>This has major consequences during refactoring when what used to be a synchronous function now needs to become an asynchronous function => all synchronous functions that used to call the synchronous function needs to be turned into asynchronous functions themselves.<p>Sometimes the ramifications go way beyond first expected.<p>Sometimes the ramifications turned to be massive.<p>This becomes worse when one realizes that synchronous function are much more readable, half the code and about 5 times faster than asynchronous ones (see <a href="http://jsperf.com/asynch-cost" rel="nofollow">http://jsperf.com/asynch-cost</a>)<p>Eventually the idea of refactoring a synchronous function into an asynchronous function becomes a source of worries.<p>And that, my friends, is not something easy to figure out and is what I call "node anxiety"
For #1, why not suppy a success and failure callback function to your doSomeAsyncCall function? There is no reason to muddle those two lines of logic together (which is the real reason for the described error).<p>And for #2, Relying on javascript hoisting functions isnt a smart way to keep your code organized.