4

I need a distinct sound to play when a error occurs. The error is the result of a problem with one of perhaps two hundred barcodes that are being inputted in rapid fire. The event queue seems to handle keyboard input (which the barcode scanner emulates) first, and playing of my sound second. So if the barcodes are scanned quickly, the error sound stays in the queue, being bumped by the next scan.

Can I manipulate the priority of the queue?

dacracot
  • 22,002
  • 26
  • 104
  • 152
  • What is this queue you speak of? Care to share relevant portions of code or at least a sample that illustrates what this queue is? – Jason Bunting Nov 11 '08 at 19:45
  • 1
    It is not code that I have written. It is the event queue built into all JavaScript engines. I happen to be using Firefox's. – dacracot Nov 11 '08 at 19:53
  • Yes but how are you interacting with it? How are the barcodes validated and on what event. Is it on a keypress event or a blur event of a textbox? What is then fired that causes the sound to play? I think your question is to vague for anyone to be of much use. – James Hughes Nov 12 '08 at 15:08
  • I think his question was pretty clear. He's handling keypress events, as he said, but their priority is too high -- his question is "Can I manipulate the priority of [events in the event] queue". – BrainSlugs83 Jun 29 '12 at 05:26

3 Answers3

1

Javascript is not multi-threaded, so option 2 won't work. And I suspect that the event queue you speak of is the OS's event queue, which isn't likely to accessible from a browser, if at all.

Beyond that, I'm having a little trouble understanding your problem. What is firing the error sound? Is it a keyup, etc event or is it a server side validation that returns an error code or something else?

sblundy
  • 60,628
  • 22
  • 121
  • 123
  • 1
    I'm creating an embed object in the DOM with src=error.wav, hidden=true, and autostart=true. The sound plays, but only after the queue clears. – dacracot Nov 11 '08 at 19:42
  • 1
    There are arrays which are searched client side for error determination. – dacracot Nov 11 '08 at 19:44
1

What I can guess from your problem is User stops scanning when he hears Error sound. If that is true, why wait for user to stop scan.

You can perform any of the following.

As soon as error occurs stop entering data. you can set 'keypress' to return false. also you can set a buffer on keypress event which first store input data and then return false. This way you will data after error has occurred.

BigBoss
  • 413
  • 8
  • 23
  • I think you have it backwards -- the error sound can't play until AFTER they stop scanning (read the question again) -- if it was working, why would he ask? ;-) -- Though, I have to agree, returning false from the event is probably a good bet. – BrainSlugs83 Jun 29 '12 at 05:29
0

What if you try to delay the scans (using setTimeout()), allowing the sounds to start and finish between them?

Kon
  • 27,113
  • 11
  • 60
  • 86
  • I'm afraid that if I delay the scan, I will miss the data. Since it is the user that pulls the trigger on the scan, I can not necessarily slow them down. – dacracot Nov 11 '08 at 19:54
  • Huh, I guess I don't understand how your scanner is interacting with the browser...that would be useful to know. You can still capture user input (from a keyboard, let's say) and allow other things to happen if you coordinate it correctly, regardless of how fast the user is. – Jason Bunting Nov 11 '08 at 20:00
  • Okay, what JavaScript event fires when something is scanned and what does an event handler for that look like? Or how does it emulate it? Answers would help us help you. – Jason Bunting Nov 11 '08 at 20:05
  • How would setTimeout help here? Wouldn't that just add more events to the event queue? .. It seems that his issue is that his DOM object creation is left pending until all of his events have finished firing. – BrainSlugs83 Jun 29 '12 at 05:33