Skip to main content

ThreadDispatcherInit

Struct ThreadDispatcherInit 

Source
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

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more