26 2 / 2013
Parallel.js allows you to spawn a worker containing one or more functions, defined in your parent thread rather than as a separate file. You just pass the function names and some arguments to call the function with, and Parallel.js will spawn a worker thread, run the function with the passed arguments, and send the result back to the main thread asynchronously using a Promise based API.
There is also a MapReduce API for processing large datasets that will split the data into chunks to be processed in parallel by an arbitrary number of worker threads. When all of the processing is complete, the result is merged back together and returned to the main thread.
As web applications do more of their processing on the client side, we will need to take advantage of the multicore machines that modern systems have in order to maintain a good user experience. As a rule of thumb, we never want to do a lot of processing on the main UI thread since the user will notice the lag. Web Workers are great, but in general quite difficult to use. I’m glad to see libraries beginning to make things easier in this department.