Created
November 27, 2013 04:47
-
-
Save austo/7670799 to your computer and use it in GitHub Desktop.
Revisions
-
austo created this gist
Nov 27, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ function first(cb) { console.log('hello from first...'); cb(); } function second(cb) { console.log('hello from second...'); cb(); } function third(cb) { console.log('hello from third...'); cb(); } function done() { console.log('hello from done'); } function series(functions, callback) { var funcs = functions.slice(0); function processNext(err) { if (err) { return callback(err); } var args = Array.prototype.slice.call(arguments), func = funcs.shift(); if (func) { // remove error argument args.shift(); } else { func = callback; } args.push(processNext); func.apply(this, args); } processNext.call(this); } series([first, second, third], done);