You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
666 B
28 lines
666 B
2 years ago
|
var noop = require('./noop');
|
||
|
var nextTick = require('./nextTick');
|
||
|
var restArgs = require('./restArgs');
|
||
|
exports = function(tasks, cb) {
|
||
|
cb = cb || noop;
|
||
|
var current = 0;
|
||
|
var taskCb = restArgs(function(err, args) {
|
||
|
if (++current >= tasks.length || err) {
|
||
|
args.unshift(err);
|
||
|
nextTick(function() {
|
||
|
cb.apply(null, args);
|
||
|
});
|
||
|
} else {
|
||
|
args.push(taskCb);
|
||
|
tasks[current].apply(null, args);
|
||
|
}
|
||
|
});
|
||
|
if (tasks.length) {
|
||
|
tasks[0](taskCb);
|
||
|
} else {
|
||
|
nextTick(function() {
|
||
|
cb();
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
|
||
|
module.exports = exports;
|