#web-worker #worker #web

launch-worker

在Web Worker中启动Wasm代码

1个不稳定版本

0.1.0 2023年2月26日

1145WebAssembly

MIT/Apache

5KB
72

启动Web Worker

高度WIP。当前使用

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());
    }
}

依赖项

~6.5–8.5MB
~168K SLoC