My AngularJS requirement involves the following:
for (var i = 0, len = self.Scope.data.length; i < len; i++)
{
var data = self.Scope.data[i];
var self = this;
//Executing First asynchronous function
self.EcritureService.createNewData(data).then(() => {
})
//Executing Second asynchronous function
self.OperationService.getOperation(data.idOperation).then((operation) => {
})
//Executing Third asynchronous function
self.AccountService.getAccount(data.codeCompte).then((compte) => {
currentAccount = compte;
currentAccount.montant = currentAccount.montant+data.montant;
})
//Executing Fourth function depending on the third result to execute sequentially
self.AccountService.updateAccount(currentAccount).then(() => {
})
}
// Once all promises from the fetch loop are resolved, I need to proceed with additional steps to update the operation fetched in the second function
I require the loop iterator to wait until all promises are resolved before proceeding to the next step and ensuring that all tasks are completed before moving to the final functionality outside the loop block.