Is there a method to delay the execution of a specific line of code until multiple API calls have all returned?
Typically, I follow this pattern:
APIService.call(parameter).then(function(response) {
// Do something
callBack();
});
This approach works well as callBack()
is only triggered after the response from APIService.call()
.
However, what if I have three separate API calls like this:
$scope.var1 = APIService.call1(parameter)
$scope.var2 = APIService.call2(parameter)
$scope.var3 = APIService.call3(parameter)
If I want my callback function to be invoked only after all three calls have completed, with the delay being determined by the slowest call, how can this be achieved without nesting then
statements and maintaining asynchronous behavior for all three calls?
Is there a solution for this scenario?