Clone in a terminal:
worker.js
examples/threads2/static/ - Remove threads with shared memory commit 9c53342
// 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.
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.init_thread_runner(event.data);
    };
};

File history (2 commits)

321ec6b Johan Mattsson - johan.mattsson.m@gmail.com
Remove threads with shared memory
Remove threads with shared memory
c99003a Johan Mattsson - johan.mattsson.m@gmail.com
More thread ideas
More thread ideas

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112