Sending SharedArrayBuffer to a Web Worker

Now that we know how to create and use a SharedArrayBuffer, we can use one to share data between the main thread and workers. As mentioned previously, this has an advantage over posting JavaScript objects, in that the data doesn't need to be copied; it is shared.

In this recipe, we'll see how to share a SharedArrayBuffer with a worker, and post the result back to the main thread.

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.