Skip to content

Instantly share code, notes, and snippets.

@justgord
Created March 23, 2011 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justgord/882771 to your computer and use it in GitHub Desktop.
Save justgord/882771 to your computer and use it in GitHub Desktop.
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