Last active
September 2, 2017 01:23
-
-
Save patmigliaccio/97c75b4978d8bc763f121fdd2404341a 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 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