How to do it...

  1. Open your command-line application, and navigate to your workspace.
  2. Create a new folder named 05-06-sending-shared-array-to-worker.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  4. Create a main.js file with an onMessage function that logs out the result and type members of the received message data:
function onMessage(message) { 
  const { result, type } = message.data; 
  console.log('result from worker operation: %s', type, result); 
} 
  1. Create a main.js file with a main method that defines constants for NUM_COUNT, BYTES_FOR_32_BIT, ARRAY_SIZE, and MAX_NUMBER:
export function main() { const NUM_COUNT = 2048; const BYTES_FOR_32_BIT = 4; const ARRAY_SIZE = NUM_COUNT * BYTES_FOR_32_BIT; const MAX_NUMBER ...

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.