Created
November 11, 2017 18:25
-
-
Save alextanhongpin/c59c992f4a34161764948cd1690b10b0 to your computer and use it in GitHub Desktop.
Serial promise with bluebird. The next function will only execute after the first is completed.
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
const Promise = require('bluebird') | |
function doWork (val) { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(val) | |
}, 2000) | |
}) | |
} | |
async function main () { | |
const ok = await Promise.all(Array(10).fill(0)) | |
.map((_, i) => doWork(i), { concurrency: 1 }) | |
console.log(ok) | |
} | |
main().then(console.log).catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment