pub struct ThreadDispatcherInit { /* private fields */ }Expand description
Thread dispatcher initialization.
The thread dispatcher must be initialized prior to spawning threads. Please refer to Creating the thread dispatcher in the book.
§Terminating the thread dispatcher
Having the thread dispatcher alive will keep the JS Event Loop alive, which will prevent
non-browser runtimes such as NodeJS from exiting. In this case you need to manually call
wasm_bindgen_spawn::terminate_dispatcher to drop
the thread dispatcher which in turn causes the dispatcher worker to terminate.
Implementations§
Source§impl ThreadDispatcherInit
impl ThreadDispatcherInit
Sourcepub fn create_dispatcher_promise(self) -> Promise
pub fn create_dispatcher_promise(self) -> Promise
The same as create_dispatcher but wraps the Rust future
in a JS Promise, which can then be sent back to the JS side and await-ed.
This is useful if your project does not use async Rust at all in other places
and you don’t want to add wasm-bindgen-futures as a dependency.
Note internally this still uses the async runtime
provided by wasm-bindgen-futures (now js_sys::futures) which is what the
#[wasm_bindgen] macro uses under the hood for async functions.
Sourcepub async fn create_dispatcher(self) -> Result<(), JsValue>
pub async fn create_dispatcher(self) -> Result<(), JsValue>
Spawn the dispatcher worker and wait for it to become ready
If a JS exception occurs, it is returned as an Err.
§Panics
Panics if the dispatcher is already initialized. Note you only need to initialize the dispatcher once across the shared memory instance. You don’t need to initialize it in each thread.