-
SummaryHow can I use ES Modules in a Web Worker to import wasm-loading JS? Additional DetailsThe example assumes you want to use Additionally, while this example's title is "Wasm in Web Worker", it would be more aptly titled "Web Worker in Wasm" as the worker itself is spawned in the Rust that's compiled to wasm and
let w = new Worker("worker.js", { "type": "module" });
w.postMessage(..);
import { add } from "wasm.js"
self.onmessage = async e => {
add(e.a, e.b);
};
export function add(a, b) {
const ret = wasm.add(a, b);
return ret >>> 0;
}
function initSync(module) {
// contents of autogen func omitted for brevity
}
async function __wbg_init(input) {
// contents of autogen func omitted for brevity
}
export { initSync }
export default __wbg_init;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn add(a: u32, b: u32) -> u32 {
a + b
} Certainly this is wrong. I know that there is logic missing in
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Answered on Discord:
|
Beta Was this translation helpful? Give feedback.
Answered on Discord: