If I understand the question, it sounds like you want to write a method in
JavaScript in your HTML, and have it be executed when a worker is created?
Do you want it to run in the HTML (on the main thread) or in the worker?

If in HTML, then you can modify the code that creates workers (not sure
where, but looking for new Worker() in src/ should find it). Or, you might
just patch Worker itself in the main scope, replace it with another method
that wraps around it. Overall I don't think we have a nice way to do that
right now.

If in the worker, then you can't directly do that - functions can't be
passed from workers, only JSON-type data.

On Thu, Apr 21, 2016 at 7:55 AM, Kerby Geffrard <[email protected]>
wrote:

> Hi,
>
> I was wondering if there's a way to attach any function to any worker that
> Emscripten create. I want to do that because I want to add an event
> listener to all of my threads.
>
> What I would like to do:
>
>
>    - I want to be able to add a function in my shell.html (Let's call it
>    *onNewWorker*)
>    - And when emscripten create a Worker because of a pthread in my
>    project, *onNewWorker *is called with my worker passed in argument
>    - So since inside of my *onNewWorker *function, I can add event
>    listener with my worker, all my pthread have the event listener that I want
>
>
> I want to do this because I need to add an event listener for when my C++
> thread send message with EM_ASM*. This is needed because I want to send a
> message from my thread to the main thread that trigger an
> `alert('message')` since we can't use alert() from workers.
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to