Ghost/core/server/lib/promise/sequence.js
kirrg001 f83cbf6117 Moved pipeline/sequence to lib/promise
refs #9178

- continue with killing our global utils folder
- i haven't found any better naming for lib/promise
- so, require single files for now
- instead of doing `promiseLib = require('../lib/promise')`
- we can optimise the requires later
2017-12-13 22:20:02 +01:00

18 lines
441 B
JavaScript

var Promise = require('bluebird');
/**
* expects an array of functions returning a promise
*/
function sequence(tasks /* Any Arguments */) {
var args = Array.prototype.slice.call(arguments, 1);
return Promise.reduce(tasks, function (results, task) {
return task.apply(this, args).then(function (result) {
results.push(result);
return results;
});
}, []);
}
module.exports = sequence;