How can I prevent event handlers from simultaneously managing multiple events in javascript?

advertisements

How do I prevent JavaScript from handling two events at once? I have an event handler declared such as document.addEventListener('keydown',function(e) {},false) in this case, I do not want the handler to handle any events until it has finished with the current one.


Javascript is single threaded so the current event processing will finish before the next event is triggered. You do not have to do anything to guarantee that only one event is processed at a time.

You can learn more about this topic from these other posts:

How does JavaScript handle AJAX responses in the background? (describes how event queues in javascript operate)

Can JS event handlers interrupt execution of another handler?

Race conditions with JavaScript event handling?