Can I change the priority of an event queue in JavaScript?

I need a separate sound to play when an error occurs. The error is the result of a problem with one of perhaps two hundred barcodes that are entered into rapid fire. It seems that the event queue processes the keyboard input (which first emulates a barcode scanner), and the second - the second. Therefore, if the barcodes are scanned quickly, the error sound remains in the queue, gaining the next scan.

Can queue priority be controlled?

+4
source share
3 answers

Javascript is not multithreaded, so option 2 will not work. And I suspect that the event queue you are talking about is an OS event queue that is unlikely to be accessible from the browser, if at all possible.

Also, I have problems understanding the problem. What causes the error sound? Is this a keyup event, etc, or is it a server side check that returns an error code or something else?

+1
source

What can I guess from your problem, the user stops scanning when he hears the error sound. If so, why wait until the user stops scanning.

You can do any of the following:

As soon as an error occurs, stop entering data. you can set 'keypress' to return false. You can also set a buffer on a keypress event, which first stores the input and then returns false. Thus, you will receive data after an error occurs.

+1
source

What if you try to postpone scanning (using setTimeout() ), allowing you to start and end sounds in between?

0
source

All Articles