emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

Use addEventListener in a few places instead of registering on to .onmessage

Open juj opened this issue 2 years ago • 3 comments

Use addEventListener in a few places instead of registering on to .onmessage so that end users can utilize the .onmessage themselves.

Addresses #20192.

juj avatar Sep 12 '23 11:09 juj

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?

sbc100 avatar Sep 12 '23 14:09 sbc100

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.

sbc100 avatar Sep 12 '23 14:09 sbc100

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]?

sbc100 avatar Oct 02 '24 17:10 sbc100

Closing old stale PR.

juj avatar Aug 16 '25 06:08 juj