How can I skip a function if the executing time too long.
For example I have 3 functions :
function A(){
Do something.. ..
}
function B(){
Do something.. ..
}
function C(){
Do something.. ..
}
A();
B();
C();
So for example for some reason function B have infinity loop inside, and keep running. How can I skip function B and go to function C if function B executing too long ?
I tried this but seem not working :
try {
const setTimer = setTimeOut({
throw new Error("Time out!");
},500);
B();
clearInterval(setTimer);
}
catch(error){
console.warn(error);
}
But seem not working.
Update 1 : FYI, I didn't do any anti-pattern but function B is something in NPM and I submitted issues to the owner of repo. Just try to dodge the bullet so I have some extra times until the fix. Thanks guys for helping me so far :)