I have 7 async functions calls after which I need to execute a function. Sample structure of code.
Code
<script>
(function(){
f1();
f2();
f3();
f4();
f5();
f6();
f7();
// execute final() when f1-f7 async function have executed.
// All the function have ajax request
final();
});
</script>
My Current Approach
<script>
(function(){
var finalExecuted = false;
f1();
f2();
f3();
f4();
f5();
f6();
f7();
// execute final() when f1-f7 async function have executed.
// All the function have ajax request
setInterval(function(){
if($.active == 0 && !finalExecuted) {
final();
finalExecuted = true;
} },500);
});
</script>
Is this the correct approach to do? All the function f1-f7 are different functions and fetch different values from API's.