Terminating a single parent-worker connection

When this code is called, the connection between the parent and worker is shut down, and you'll no longer be able to make use of that worker object to post messages:

// script.jsconst awesomeworker = new SharedWorker('myworker.js');awesomeworker.port.start(); // some processing and some workawesomeworker.port.close();awesomeworker.port.postMessage("Are you still alive?"); // does not work | no effect

Although the worker still lives, it loses its connection from the script which calls .port.close().

After the connection is closed, the worker won't be able to send/receive messages from the main script. However, the main script can always call the shared web worker again by creating a new instance ...

Get Learn ECMAScript - Second Edition 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.