Is it possible to do something like this:
var citiesPromise = citiesService.getCities();
var usersPromise = usersService.getUsers();
citiesPromise.then(function(citiesResult) {
// cities will load very quick, and I can do something with them
);
$q.all([citiesPromise, usersPromise]).then(function(results) {
// users will probably load after cities, but both results must be available
);
In other words, I need a promise that will behave as an event dispatcher, and every 'then' call on that promise is as if an event listener was added to that promise. When promise is resolved or rejected, all event listeners are notified.
Can this be achieved, or should in this case stick only to the '$q.all' as a single point where all results are processed?
What would I gain by doing this? Maybe in this case not much, but if I was to have 10 or more ajax calls, it would be cool if a page loads gradually, not wasting time waiting for http requests...