Considering the following code in ui5/javascript. Inside for loop the code should be executed always in the sequence: getData1, getData2, fnc1(i), getData3, getData4, fnc2(i) for each "i" before calling function fnc3(). As of now fnc3 is called before i is incremented:
for (var i = 0; i <= intNum; i++) {
getData1(url1, true).then(function() {
getData2(url2, true).then(function() {
fnc1(i);
getData3(url3, true).then(function() {
getData4(url4, true).then(function() {
fnc2(i);
})
})
})
})
}
fnc3();
All four getData functions do some operations and then return a promise.
function getData() {
var oModel = new JSONModel();
return oModel.loadData(url, true); //asynchronous loading data and returns a promise
}
Any solution how can I make it work? Any help appreciated. Thanks
for()
loop inside a Promise and callfunc3()
inside the then of that promise. - Randy Casburn