Skip to content

Instantly share code, notes, and snippets.

@justgord justgord/serialq.js
Created Mar 23, 2011

Embed
What would you like to do?
serialq implementation - call functions sequentially for Node.js
exports.SerialQueue = function()
{
var sq =
{
funcs : [],
next : function()
{
var Q = this;
var f = Q.funcs.shift();
if (f)
f(function() {Q.next();});
},
add : function(f)
{
this.funcs.push(f);
},
run : function()
{
this.next();
}
};
return sq;
}
var SerialQueue = require('serialq').SerialQueue;
{
var Q = SerialQueue();
Q.add(do_aaa);
Q.add(do_bbb);
Q.add(do_ccc);
Q.add(function(next) {
console.log('\nall done\n');
next();
});
Q.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.