The aim of the Parallel.js
library is to make interacting with web workers as seamless as possible. In fact, it handles one of the key goals of this book—it hides the concurrency mechanism and allows us to focus on the application that we're building.
In this section, we'll look at the approach taken by Parallel.js
for worker communication and the general approach of passing code to workers. Then, we'll walk through some code that uses Parallel.js
to spawn new worker processes. Lastly, we'll explore the built-in map/reduce capabilities that the library has to offer.
All the workers that we've used so far in this book have been our own creation. We implemented message event handling in our workers that computed some value, then posted a response. With Parallel.js
, we don't implement workers. Instead, we implement functions, which are then passed to workers that are managed by the library.
This takes care of a few headaches for us. All our code is implemented in...