I'm trying to wait for an API to load, however my test code below doesn't seem to be taking the timeout delay into account as it's looping too quickly.
var google = false;
function test(check = false) {
if (!check) {
console.log('append the api');
check = true;
}
if (check) {
console.log('check api is loaded');
if(!google){
console.log('not loaded');
setTimeout(test(true), 10000);
return;
} else {
console.log('loaded');
}
}
}
This code should just keep displaying the 2 console.log's until the google variable is changed to true.
I'm unable to change this though as the browser freezes up due to so many loops.