wasmWorker example: Add option to receive empty response when QR not found #87
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
N/A
Description of changes:
In my own app, I was unable to send messages to the worker too frequently, lest I send messages while it's still working, leading to the worker stalling over a pile of work that it can never catch up on, delaying the time it takes to actually register a successful scan.
In my use case, I was able to remedy this by having the worker respond with data/type undefined, and then once the app receives word that the worker is no longer busy, it's free to send another snapshot from the camera. This significantly improved the performance of my scanner, because I can essentially always keep the worker busy & not be afraid of piling it with more work than it can handle.
I added it under the optional
event.data.alwaysRespond
, because this is a change in the API behavior, and therefore the programmer must update the way they call the worker in order to take advantage of this change. (i.e., if you requestalwaysRespond: true
, then you can no longer assume thatdata
is present when receiving a message from the worker. So it makes sense to me to have this an "opt-in" change.Side note: I noticed that public/jsQrWorker.js has a console.log statement where wasmWorker doesn't. I didn't include a change to it in this PR cuz it's outs of the scope of this issue, but I thought I'd mention it if you didn't realize it was there.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.