Ghost/core/server/utils/pipeline.js
2014-08-23 17:15:40 +00:00

22 lines
556 B
JavaScript

var Promise = require('bluebird');
function pipeline(tasks /* initial arguments */) {
var args = Array.prototype.slice.call(arguments, 1),
runTask = function (task, args) {
runTask = function (task, arg) {
return task(arg);
};
return task.apply(null, args);
};
return Promise.all(tasks).reduce(function (arg, task) {
return Promise.resolve(runTask(task, arg)).then(function (result) {
return result;
});
}, args);
}
module.exports = pipeline;