I've been attempting to ensure that an API is fully loaded before proceeding, but the test code below doesn't seem to be properly implementing the timeout delay. As a result, it seems to be running through the loop too quickly.
var google = false;
function test(check = false) {
if (!check) {
console.log('appending the api');
check = true;
}
if (check) {
console.log('checking if api is loaded');
if(!google){
console.log('api not yet loaded');
setTimeout(test(true), 10000);
return;
} else {
console.log('api loaded successfully');
}
}
}
This code should continue to display the two console.log messages until the google variable is set to true.
However, I'm faced with a dilemma as the browser becomes unresponsive due to an excessive number of loops being generated.