Last active
December 16, 2015 21:28
-
-
Save bdeitte/5499450 to your computer and use it in GitHub Desktop.
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
var Q = require('q'); | |
var allPromises = function (arrayOfThings) { | |
var promises = []; | |
arrayOfThings.forEach(function(aThing) { | |
console.log('updating a thing: ' + aThing); | |
var promise = Q.fcall(function () { | |
console.log("in func promise"); | |
return 'something'; | |
}) | |
.delay(1000) | |
.done(function() { | |
console.log('done with func promise'); | |
}); | |
promises.push(promise); | |
}); | |
console.log('returning a promise'); | |
return Q.allResolved(promises); | |
}; | |
allPromises(['a', 'b', 'c']) | |
.done(function() { | |
console.log('done with everything'); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Switching "done" to "then" in the function is the answer, so that the "promise" variable actually has a promise.