chemicstry / wasm_thread

A rust `std::thread` replacement for wasm32 target
Apache License 2.0
123 stars 16 forks source link

How do I get the `DedicatedWorkerGlobalScope`? #7

Closed felipellrocha closed 2 years ago

felipellrocha commented 2 years ago

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

DouglasDwyer commented 2 years ago

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.

chemicstry commented 2 years ago

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