I have a function that gets called every time the enter key is pressed. I need to make it so that the function will NOT be called if you press the enter key again, IF and when the function has not finish executing yet. Only when the function has finished executing, will it be called again if you press the enter key again. How would I do this in jQuery, or JavaScript?
onKeyDown = 'if(event.keyCode==13) someFunction()'
function someFunction() {
//some codes
//some setTimeouts
}
Simply set a Boolean when done and check it before executing the function.
onKeyDown = 'if(event.keyCode==13) { if (!finished){someFunction();}'
var finished = false;
function someFunction() {
finished = false
//some codes
//some setTimeouts
finished = true;
}
Though, as Luis points out, Javascript is single threaded and so you shouldn't be running into the problems you describe unless I am not understanding your problem fully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With