qualia:workers

v0.0.1Published 6 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Workers

The qualia:workers package provides an easy way to parallelize code across multiple processes and fibers on the server. It's as easy as:

1import Workers from 'meteor/qualia:workers';
2
3let jobs = Workers.map([1, 2, 3], x => x*x);
4console.log(Workers.waitAll(jobs));
5// => [1, 4, 9]

Installation

$ meteor add qualia:workers

Usage

Using qualia:workers is very simple. The usage shown in the introduction is really all there is to it. However, there are two very important things to keep in mind:

  1. Workers run in their own processes, which means that there is no shared global state between them. It is a distinct instance of your application.

  2. The function passed to Workers.map is stringified before being sent to a worker process. This means that it does not have access to the local scope in which it is declared (aka the closure is lost). So the following code would throw an error:

1let hello = 'hello';
2Workers.map(['yo', 'sup', 'hello'], greeting => {
3  return hello === greeting;
4});

This fails because the variable hello was declared outside of the function passed to Workers.map.