After completing a Promise within a for-loop, I am attempting to formulate a response.
Although I have reviewed these questions, my scenario remains unaddressed.
The methodGetOrders and methodGetLines are components of an external library that must be utilized. Both imply network calls, resulting in some anticipated delay. Currently, the function simply returns '0' as it does not await the resolution of the inner promise. While acknowledging the inability to directly 'wait' for promise completion, how can I attain the accurate value of counter in the response?
doWorkMainFunction() {
methodGetOrders()
.then(orderList => {
var counter=0;
for (var i=0; i< orderList.length; i++) {
methodGetLines()
.then (lineData => {
if (someCondition) { counter++; }
} // end of inner THEN
} // end FOR loop
return counter; // This always returns '0'
} // end of outer THEN
}