Skip to content

Instantly share code, notes, and snippets.

@cherihung
Created February 16, 2016 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cherihung/998a4f8fcbfb07618c2f to your computer and use it in GitHub Desktop.
Save cherihung/998a4f8fcbfb07618c2f to your computer and use it in GitHub Desktop.
Pattern for collection deferred promises at once
function fetchFromService(data) {
var promises = [];
_.each(data, function(item) {
var deferred = $q.defer();
someService.getItem(item).then(function(response) {
deferred.resolve(response);
});
promises.push(deferred.promise);
});
return $q.all(promises);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment