Skip to content

Instantly share code, notes, and snippets.

@patmigliaccio
Last active September 2, 2017 01:23
Show Gist options
  • Save patmigliaccio/97c75b4978d8bc763f121fdd2404341a to your computer and use it in GitHub Desktop.
Save patmigliaccio/97c75b4978d8bc763f121fdd2404341a to your computer and use it in GitHub Desktop.
patmigliaccio.com/async-fishing - 12/11/16
function allFulfilled(answerPs) {
let countDown = answerPs.length;
const answers = [];
if (countDown === 0) { return answers; }
const deferredResult = Q.defer();
answerPs.forEach(function(answerP, index) {
Q(answerP).when(function(answer) {
answers[index] = answer;
if (--countDown === 0) { deferredResult.resolve(answers); }
}, function(err) {
deferredResult.resolve(Q.reject(err));
});
});
return deferredResult.promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment