In the previous recipe, we saw how data can be shared between the main thread and a single worker. This is helpful for move long-running operations on the main thread, which helps keep the UI responsive. However, it isn't taking full advantage of parallel processing. With very large datasets, breaking up the computation between many workers can be advantageous.
In this recipe, we'll see how to use multiple workers to produce portions of a result.
This recipe assumes you already have a workspace that allows you to create and run ES modules in your browser. If you don't, please see the first two chapters.
- Open your command-line application and navigate to your workspace.
- Create a new folder named
05-07-reading-shared-buffer-from-multiple-workers
. - Copy or create an
index.html
that loads and runs amain
function frommain.js
. - Create a
main.js
file with anonMessage
function that logs out the following members of the message data...