Last active
September 2, 2017 01:22
-
-
Save patmigliaccio/8cb519de5a21e66a816b5abb5504aa98 to your computer and use it in GitHub Desktop.
patmigliaccio.com/async-fishing 12/11/16
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
function all(promises){ | |
let len = promises.length, | |
returned = 0, | |
responses = []; | |
let totalPromise = new Promise((resolve, reject) => { | |
promises.forEach((p, i) => { | |
p.then(response => { | |
responses[i] = response; | |
}) | |
.catch(error => { | |
responses[i] = new Error(error); | |
}) | |
.then(() => { | |
returned++; | |
if (len == returned){ | |
resolve(responses) | |
} | |
}); | |
}); | |
}); | |
return totalPromise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment