Created
June 2, 2017 02:41
-
-
Save stiekel/defd3ecb7ff957cefcab28a5d9fe7888 to your computer and use it in GitHub Desktop.
Run Multi Promise as Serial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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