I'm sure this one has been done before but I don't know what it's called. npm install pend <https://github.com/superjoe30/node-pend>
It's similar to batch <https://github.com/visionmedia/batch>, but different in a couple important aspects. Here's example code from the README: var Pend = require('pend');var pend = new Pend();pend.max = 10; // defaults to Infinitypend.go(function(cb) { console.log("this function is immediately executed"); setTimeout(function() { console.log("calling cb 1"); cb(); }, 500);});pend.go(function(cb) { console.log("this function is also immediately executed"); setTimeout(function() { console.log("calling cb 2"); cb(); }, 1000);});pend.wait(function(err) { console.log("this is executed when the first 2 have returned."); console.log("err is a possible error in the standard callback style.");}); Output: this function is immediately executed this function is also immediately executed calling cb 1 calling cb 2 this is excuted when the first 2 have returned. err is a possible error in the standard callback style. So the cool thing here is that you don't have to call "wait" if you don't want to. In fact, if you set "max" to a finite number then it becomes a queue, and you just call "go" to add another item to the queue. You'd call wait only when you wanted to know when the queue finished flushing. Happy coding! -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
