Complete the code to create a new Web Worker in Deno.
const worker = new Worker(new URL('worker.js', import.meta.url), { type: '[1]' });
In Deno, Web Workers are created with type 'module' to support ES modules.
Complete the code to send a message from the main thread to the worker.
worker.[1]('Hello from main thread');
The postMessage method sends data to the worker thread.
Fix the error in the worker code to receive messages correctly.
self.[1] = (event) => { console.log('Message from main:', event.data); };
postMessage instead of onmessage to receive messages.The worker listens for messages using the onmessage event handler.
Fill both blanks to send a message back from the worker to the main thread.
self.[1] = (event) => { self.[2]('Received: ' + event.data); };
sendMessage which does not exist.The worker uses onmessage to receive and postMessage to send messages.
Fill all three blanks to properly terminate the worker after receiving a message.
worker.[1] = (event) => { console.log('Worker says:', event.data); worker.[2](); worker.[3] = null; };
onerror or onclose instead of onmessage.terminate() to stop the worker.The main thread listens with onmessage, calls terminate() to stop the worker, and clears the onmessage handler.
