Skip to content

Instantly share code, notes, and snippets.

@alextanhongpin
Created November 11, 2017 18:25
Show Gist options
  • Save alextanhongpin/c59c992f4a34161764948cd1690b10b0 to your computer and use it in GitHub Desktop.
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.
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