Created
March 23, 2011 08:01
-
-
Save justgord/882771 to your computer and use it in GitHub Desktop.
serialq implementation - call functions sequentially for Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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