Have a question about synchronizing nested promises when using $q in Angular. Will the following code ensure that the entire chain of promises is waited for? Meaning will the nested calls to services that return promises be waited for in the $q.all block?
var call1 = service1.get('/someUr').then(function(){
return service2.get('/someUrl2'); //returns promise
});
var call2 = service3.get('/someUr').then(function(){
return 'hello';
});
var call3 = service4.get('/someUr').then(function(){
return service3.get('/someUrl3');//returns promise
});
$q.all(call1,call2,call3).then(function(){
console.log('All asynch operations are now completed');
});
Basically: Is there a chance with the current code that the then of $q.all will execute before all the nested promises are resolved? Or is it recursive?
$q.all()
will wait forcall1
,call2
andcall3
to resolve together before triggering thethen()
function, but the nested async calls returned fromcall1
andcall3
will not be waited on. – Twylatwyman