-
-
Save Raynos/4405173 to your computer and use it in GitHub Desktop.
This file contains 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 inOrder = require("in-order") | |
, slice = Array.prototype.slice | |
// un-tested, might work | |
module.exports = serial | |
function serial(operations) { | |
return function () { | |
var args = slice.call(arguments) | |
, exit = args.pop() | |
inOrder(operations, function (operation, callback) { | |
args.push(next) | |
operation.apply(null, args) | |
function next(err) { | |
if (err) { | |
return exit(err) | |
} | |
args = slice.call(arguments, 1) | |
callback() | |
} | |
}, function finish(err) { | |
if (err) { | |
return exit(err) | |
} | |
args.unshift(null) | |
exit.apply(null, args) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment