Skip to content

Instantly share code, notes, and snippets.

@DimaDaxDadeco
Last active February 11, 2019 17:38
Show Gist options
  • Save DimaDaxDadeco/63cfa06a6cbc3f90ad6f4395c7e63824 to your computer and use it in GitHub Desktop.
Save DimaDaxDadeco/63cfa06a6cbc3f90ad6f4395c7e63824 to your computer and use it in GitHub Desktop.
function all(promises) {
return new Promise(function(resolve,reject) {
var count = promises.length
var result = []
var checkDone = function() {
if (--count === 0) {
resolve(result)
}
}
promises.forEach(function(p, i) {
p.then(function(x) { result[i] = x }, reject).then(checkDone)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment