I have a function that makes some server calls:
function doCalls(options) {
var deferred = $q.defer;
myService.doCallOne(options).then(function(response){
myService.doCallTwo().then(function() {
deferred.resolve();
});
});
return deferred.promise;
}
I have an array of different options and I want to create an array of promises to pass to $q.all
, so I do this:
var promiseArray = [];
_.each(optionArray, function(options) {
promiseArray.push(doCalls(options));
});
Then I try to wait for them to resolve:
$q.all(promiseArray).then(function() {
doNextPart();
});
Problem is, doNextPart()
seems to be getting called before any of my promises resolve. Am I doing anything obviously wrong here?