Skip to content

Instantly share code, notes, and snippets.

@stiekel
Created June 2, 2017 02:41
Show Gist options
  • Save stiekel/defd3ecb7ff957cefcab28a5d9fe7888 to your computer and use it in GitHub Desktop.
Save stiekel/defd3ecb7ff957cefcab28a5d9fe7888 to your computer and use it in GitHub Desktop.
Run Multi Promise as Serial
var Promise = require('bluebird');
function getP (t) {
return new Promise((resolve, reject) => {
console.time(t);
setTimeout(() => {
console.log('\none Promise', t);
console.timeEnd(t);
return resolve();
}, t);
});
}
let qs = [];
for(var i = 0; i <= 3; i++ ) {
qs.push(Math.floor(Math.random() * 2000));
}
console.log('qs:', qs);
let doAll = Promise.resolve(qs).map(getP, {concurrency: 1});
doAll.then(() => {
console.log('all Done');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment