September 2018
Intermediate to advanced
328 pages
9h 10m
English
Create a new file in the /src directory named WasmWorker.js and populate it with the following contents:
/** * Web Worker associated with an instantiated Wasm module. * @class */export default class WasmWorker { constructor(workerUrl) { this.worker = new Worker(workerUrl); this.listenersByType = {}; this.addListeners(); } // Add a listener associated with the `type` value from the // Worker message: addListenerForType(type, listener) { this.listenersByType[type] = listener; } // Add event listeners for error and message handling. addListeners() { this.worker.addEventListener('error', event => { console.error(`%cError: ${event.message}`, 'color: red;'); }, false); // If a handler was specified using the ...Read now
Unlock full access