Stop an executing function
There's a piece of code that runs as a function called upon key stroke, I want to stop execution of the function on pressing another key stroke both outside and inside of the running function, here's the pseudocode.
$(document).on("keydown", function(e){
switch e.key {
case "a" : /*run*/ myFunc();
case "b" : /*stop*/ myFunc();
}
})
function myFunc(){
Some Loop(){
$(document).keydown(/*stop*/ myFunc());
}
}
How do I make it stop in both ways, obviously to run doesn't need anything, but calling the function, but how can I stop the executing function ?