#web-worker #worker #web

launch-worker

Launch Wasm code in web workers

1 unstable release

0.1.0 Feb 26, 2023

#964 in WebAssembly

24 downloads per month

MIT/Apache

5KB
72 lines

Launch web worker

Highly WIP. Current usage:

fn startup() {
    let worker = worker_from_runner("MyRunner", "my_pkg_name").unwrap();
}

#[wasm_bindgen]
pub struct MyRunner;

#[wasm_bindgen]
impl MyRunner {
    pub fn new() -> Self {
        Self
    }

    pub fn init(&self) {
        console::log_1(&JsValue::from_str("MyRunner initialized"));
    }

    pub fn onmessage(&mut self, msg: MessageEvent) {
        console::log_1(&format!("MyRunner received: {msg:?}").into());
    }
}

Dependencies

~6.5–9MB
~171K SLoC