I understand that, but I feel like a majority of the javascript async code I've seen has all been in this format. By chance, do you have an example of handler which would wait for multiple async requests to complete?
Here's a very simple version (which I admit to still using occasionally)
RequestHandler = {
numberOfRequests: 3
makeRequests: function() {
var __this = this;
a(function() {
// Parse Data
__this.completeRequest();
})
b(function() {
// Parse Data
__this.completeRequest();
})
c(function() {
// Parse Data
__this.completeRequest();
})
},
completeRequest: function() {
this.numberOfRequests--;
if(this.numberOfRequests == 0 ) this.doDone();
}
doDone: function() {
// We now have all data, do what we will.
}
}
RequestHandler.makeRequests();https://github.com/joyent/node/wiki/modules#wiki-async-flow
For a specific example, look at async.parallel: https://github.com/caolan/async