2018-10-05 06:00:23 +03:00
|
|
|
// synchronously, using the browser, import out shim JS scripts
|
|
|
|
importScripts('raytrace_parallel.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.
|
2019-10-18 01:29:37 +03:00
|
|
|
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;
|
|
|
|
});
|
2018-10-05 06:00:23 +03:00
|
|
|
|
2019-10-18 01:29:37 +03:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
};
|