chemicstry / wasm_thread

A rust `std::thread` replacement for wasm32 target

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I get the `DedicatedWorkerGlobalScope`?

felipellrocha opened this issue · comments

Once I'm inside of a thread, how do I get that thread's DedicatedWorkerGlobalScope?

You can use the global() function of js_sys to get the global object, and then dyn_into that into a DedicatedWorkerGlobalScope (see this issue discussing the problem). Note that, due to the way things are currently instrumented, you won't be able to post messages to the worker since the messaging API is already utilized by wasm_thread. Some additional code would need to be added in this crate to allow for posting custom messages.

Closing this, because it's a problem with web_sys. Posting messages to workers is tracked in #9