-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathweb_worker_module.js
More file actions
27 lines (23 loc) · 963 Bytes
/
web_worker_module.js
File metadata and controls
27 lines (23 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// synchronously, using the browser, import wasm_bindgen shim JS scripts
import init, {wasm_thread_entry_point} from "WASM_BINDGEN_SHIM_URL";
// Wait for the main thread to send us the shared module/memory and work context.
// Once we've got it, initialize it all with the `wasm_bindgen` global we imported via
// `importScripts`.
self.onmessage = event => {
let [ module, memory, work ] = event.data;
init({ module_or_path: module, memory }).catch(err => {
console.log(err);
// Propagate to main `onerror`:
setTimeout(() => {
throw err;
});
// Rethrow to keep promise rejected and prevent execution of further commands:
throw err;
}).then(() => {
// Enter rust code by calling entry point defined in `lib.rs`.
// This executes closure defined by work context.
wasm_thread_entry_point(work);
// Once done, terminate web worker
close();
});
};