Use addEventListener in a few places instead of registering on to .onmessage
Use addEventListener in a few places instead of registering on to .onmessage so that end users can utilize the .onmessage themselves.
Addresses #20192.
In #20192. the technique used to receive the message should work regardless of whether we use onmessage or addEventListener, no?
I.e. var origOnMsg = self.onmessage; self.onmessage = ...
The user reported that the technique didn't work for the -s MODULARIZE=1 -s EXPORT_ES6=1 case only.. are you sure this change fixes that?
The nice thing about the var origOnMsg = self.onmessage; self.onmessage = ... technique is that the user can then decide which message should ultimiately be delivered the emscripten-generated message handler. Is that possible with the addEventListener (provided by emcc) + onmessage (provided by user) case? I seem to remember that it is but it would be good to add some tests for this.
In order to test this, and in order for users to use it, can we add a new JS API 'pthreadToWorker(pthread_ptr)orgetWorker(pthread_ptr)` so that users can find the worker they might want to send a message to... and we should add a test to verify that it works.
If the idea is to allow user code communicate with pthreads vis postMessage, and we should at least add a test for that.
Should we also add some kind of officail API for it, or is it OK for folks use Pthreads.workers[phthread_ptr]?
Closing old stale PR.