- Open your command-line application and navigate to your workspace.
- Create a new folder named 05-04-stop-workers-with-terminate.
- Copy or create an index.html that loads and runs a main function from main.js.
- Create a main.js with a function named onMessage that takes a message and workers argument, logs out the type and timeout properties of message.data, and calls terminate on all the workers:
// main.js function onComplete(message, workers) { const { index, timeout } = message.data; workers.map((w) => w.terminate()); console.log( 'Result from worker (%s) after timeout (%s): %s', index, timeout ); }
- Create a main function that creates multiple workers, sets the onMessage property with a function that passes all the ...