-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
worker.js
25 lines (23 loc) · 848 Bytes
/
worker.js
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
// synchronously, using the browser, import out shim JS scripts
importScripts('pkg/will.js');
// Wait for the main thread to send us the shared module/memory. Once we've got
// it, initialize it all with the `wasm_bindgen` global we imported via
// `importScripts`.
//
// After our first message all subsequent messages are an entry point to run,
// so we just do that.
self.onmessage = event => {
let initialised = wasm_bindgen(...event.data).catch(err => {
// Propagate to main `onerror`:
setTimeout(() => {
throw err;
});
// Rethrow to keep promise rejected and prevent execution of further commands:
throw err;
});
self.onmessage = async event => {
// This will queue further commands up until the module is fully initialised:
await initialised;
wasm_bindgen.child_entry_point(event.data);
};
};