This is my requirement with AngularJS:
for (var i = 0, len = self.Scope.data.length; i < len; i++)
{
var data = self.Scope.data[i];
var self = this;
//First asynchronous function
self.EcritureService.createNewData(data).then(() => {
})
//Second asynchronous function
self.OperationService.getOperation(data.idOperation).then((operation) => {
})
//Third asynchronous function
self.AccountService.getAccount(data.codeCompte).then((compte) => {
currentAccount = compte;
currentAccount.montant = currentAccount.montant+data.montant;
})
//Fourth one relies on the third result, So it must be executed sequentially
self.AccountService.updateAccount(currentAccount).then(() => {
})
}
// After all fetch loop's promises are resolved I want to execute some instructions here for to update the operation retrieved in the second function.
I want this loop iterator wait till all promises are resolved before going on the next step than make sure that all works are done, moving to last functionality that reside outside the loop bloc