I wish to load ~10000 resources and doing this all at once during the resolve phase takes a bit too long due to certain calculations being done. So then I came to the idea to load the resources page by page sequentially, however since all these resources need to be visible (on a map) standard, user-input based pagination, doesn't really work.
I know that promises can be chained like:
promise.then(doThis).then(doThat).then(doWhat);
And I know that an array of promises can be resolved with $q.all like:
$q.all([doThis, doThat, doWhat]);
However what I want to is to call the same promise again and again in series until I hit a rejection.
Example:
function next() {
var deferred = $q.defer();
if(someCondition) {
deferred.reject();
} else {
//do something
//store data somewhere
deferred.resolve();
}
return deferred.promise;
}
Let's say that this function does some $http calls and stores the result somewhere in the service/controller. If it hits a certain condition (perhaps there aren't any pages anymore or an http error) it rejects a promise, otherwise it resolves it.
Now I'd like to do something like this pseudocode
$q.loop(next).untilError(handleError);
Where next will be called in a loop upon resolving the previous next call, until rejection.
Is something like this possible?