Skip to content

Instantly share code, notes, and snippets.

@bdeitte
Last active December 16, 2015 21:28
Show Gist options
  • Save bdeitte/5499450 to your computer and use it in GitHub Desktop.
Save bdeitte/5499450 to your computer and use it in GitHub Desktop.
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');
}
);
@bdeitte
Copy link
Author

bdeitte commented May 2, 2013

Switching "done" to "then" in the function is the answer, so that the "promise" variable actually has a promise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment