Skip to content

Instantly share code, notes, and snippets.

@jwerle
Last active February 2, 2016 17:16
Show Gist options
  • Save jwerle/9a2c0dcba2d9c5b48bf0 to your computer and use it in GitHub Desktop.
Save jwerle/9a2c0dcba2d9c5b48bf0 to your computer and use it in GitHub Desktop.
'use strict'
function * createPromises () {
let max = 5
for (let i = 0; i < max; ++i) {
yield new Promise(done => {
const to = Math.random() * i * 100
setTimeout(() => {
console.log('done %dms for i=%d', to, i)
done(i)
}, to)
})
}
}
const promises = createPromises()
const promise = Promise.all(promises)
promise.then(results => console.log('results', results))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment