javascript - Run Bluebird Promises Sequentially, without return values? -
this question has been asked in variety of ways, not quite simply.
how promise.all rewritten promise1
runs before promise2
?
var promise1 = function() { .. lots of promise stuff }; var promise2 = function() { .. lots more promise stuff }; promise.all([promise1, promise2]).then(function() { log.info("ran promise1 & promise2"); });
promise.all runs promise1 & promise2 in parallel.
you can use promise.map concurrency option set 1.
var promise1 = function () { return new promise(function (resolve, reject) { console.log("promise1 pending"); settimeout(function () { console.log("promise1 fulfilled"); resolve(); }, 1000) }) }; var promise2 = function () { return new promise(function (resolve, reject) { console.log("promise2 pending"); settimeout(function () { console.log("promise2 fulfilled"); resolve() }, 50) }) }; promise.map([promise1, promise2], function (promisefn) { return promisefn(); //make sure here return promise }, {concurrency: 1}); //it run promises sequentially //it logs //promise1 pending //promise 1 fulfilled //promise2 pending //promise 2 fulfilled