Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

workerpool

josdejong26.1mApache-2.09.2.0TypeScript support: included

Offload tasks to a pool of workers on node.js and in the browser

worker, web worker, cluster, pool, isomorphic

readme

workerpool

workerpool offers an easy way to create a pool of workers for both dynamically offloading computations as well as managing a pool of dedicated workers. workerpool basically implements a thread pool pattern. There is a pool of workers to execute tasks. New tasks are put in a queue. A worker executes one task at a time, and once finished, picks a new task from the queue. Workers can be accessed via a natural, promise based proxy, as if they are available straight in the main application.

workerpool runs on Node.js and in the browser.

Features

  • Easy to use
  • Runs in the browser and on node.js
  • Dynamically offload functions to a worker
  • Access workers via a proxy
  • Cancel running tasks
  • Set a timeout on tasks
  • Handles crashed workers
  • Small: 7 kB minified and gzipped
  • Supports transferable objects (only for web workers and worker_threads)

Why

JavaScript is based upon a single event loop which handles one event at a time. Jeremy Epstein explains this clearly:

In Node.js everything runs in parallel, except your code. What this means is that all I/O code that you write in Node.js is non-blocking, while (conversely) all non-I/O code that you write in Node.js is blocking.

This means that CPU heavy tasks will block other tasks from being executed. In case of a browser environment, the browser will not react to user events like a mouse click while executing a CPU intensive task (the browser "hangs"). In case of a node.js server, the server will not respond to any new request while executing a single, heavy request.

For front-end processes, this is not a desired situation. Therefore, CPU intensive tasks should be offloaded from the main event loop onto dedicated workers. In a browser environment, Web Workers can be used. In node.js, child processes and worker_threads are available. An application should be split in separate, decoupled parts, which can run independent of each other in a parallelized way. Effectively, this results in an architecture which achieves concurrency by means of isolated processes and message passing.

Install

Install via npm:

npm install workerpool

Load

To load workerpool in a node.js application (both main application as well as workers):

const workerpool = require('workerpool');

To load workerpool in the browser:

<script src="workerpool.js"></script>

To load workerpool in a web worker in the browser:

importScripts('workerpool.js');

Setting up the workerpool with React or webpack5 requires additional configuration steps, as outlined in the webpack5 section.

Use

Offload functions dynamically

In the following example there is a function add, which is offloaded dynamically to a worker to be executed for a given set of arguments.

myApp.js

const workerpool = require('workerpool');
const pool = workerpool.pool();

function add(a, b) {
  return a + b;
}

pool
  .exec(add, [3, 4])
  .then(function (result) {
    console.log('result', result); // outputs 7
  })
  .catch(function (err) {
    console.error(err);
  })
  .then(function () {
    pool.terminate(); // terminate all workers when done
  });

Note that both function and arguments must be static and stringifiable, as they need to be sent to the worker in a serialized form. In case of large functions or function arguments, the overhead of sending the data to the worker can be significant.

Dedicated workers

A dedicated worker can be created in a separate script, and then used via a worker pool.

myWorker.js

const workerpool = require('workerpool');

// a deliberately inefficient implementation of the fibonacci sequence
function fibonacci(n) {
  if (n < 2) return n;
  return fibonacci(n - 2) + fibonacci(n - 1);
}

// create a worker and register public functions
workerpool.worker({
  fibonacci: fibonacci,
});

This worker can be used by a worker pool:

myApp.js

const workerpool = require('workerpool');

// create a worker pool using an external worker script
const pool = workerpool.pool(__dirname + '/myWorker.js');

// run registered functions on the worker via exec
pool
  .exec('fibonacci', [10])
  .then(function (result) {
    console.log('Result: ' + result); // outputs 55
  })
  .catch(function (err) {
    console.error(err);
  })
  .then(function () {
    pool.terminate(); // terminate all workers when done
  });

// or run registered functions on the worker via a proxy:
pool
  .proxy()
  .then(function (worker) {
    return worker.fibonacci(10);
  })
  .then(function (result) {
    console.log('Result: ' + result); // outputs 55
  })
  .catch(function (err) {
    console.error(err);
  })
  .then(function () {
    pool.terminate(); // terminate all workers when done
  });

Worker can also initialize asynchronously:

myAsyncWorker.js

define(['workerpool/dist/workerpool'], function (workerpool) {
  // a deliberately inefficient implementation of the fibonacci sequence
  function fibonacci(n) {
    if (n < 2) return n;
    return fibonacci(n - 2) + fibonacci(n - 1);
  }

  // create a worker and register public functions
  workerpool.worker({
    fibonacci: fibonacci,
  });
});

Examples

Examples are available in the examples directory:

https://github.com/josdejong/workerpool/tree/master/examples

API

The API of workerpool consists of two parts: a function workerpool.pool to create a worker pool, and a function workerpool.worker to create a worker.

pool

A workerpool can be created using the function workerpool.pool:

workerpool.pool([script: string] [, options: Object]) : Pool

When a script argument is provided, the provided script will be started as a dedicated worker. When no script argument is provided, a default worker is started which can be used to offload functions dynamically via Pool.exec. Note that on node.js, script must be an absolute file path like __dirname + '/myWorker.js'. In a browser environment, script can also be a data URL like 'data:application/javascript;base64,...'. This allows embedding the bundled code of a worker in your main application. See examples/embeddedWorker for a demo.

The following options are available:

  • minWorkers: number | 'max'. The minimum number of workers that must be initialized and kept available. Setting this to 'max' will create maxWorkers default workers (see below).
  • maxWorkers: number. The default number of maxWorkers is the number of CPU's minus one. When the number of CPU's could not be determined (for example in older browsers), maxWorkers is set to 3.
  • maxQueueSize: number. The maximum number of tasks allowed to be queued. Can be used to prevent running out of memory. If the maximum is exceeded, adding a new task will throw an error. The default value is Infinity.
  • workerType: 'auto' | 'web' | 'process' | 'thread'.
    • In case of 'auto' (default), workerpool will automatically pick a suitable type of worker: when in a browser environment, 'web' will be used. When in a node.js environment, worker_threads will be used if available (Node.js >= 11.7.0), else child_process will be used.
    • In case of 'web', a Web Worker will be used. Only available in a browser environment.
    • In case of 'process', child_process will be used. Only available in a node.js environment.
    • In case of 'thread', worker_threads will be used. If worker_threads are not available, an error is thrown. Only available in a node.js environment.
  • workerTerminateTimeout: number. The timeout in milliseconds to wait for a worker to cleanup it's resources on termination before stopping it forcefully. Default value is 1000.
  • forkArgs: String[]. For process worker type. An array passed as args to child_process.fork
  • forkOpts: Object. For process worker type. An object passed as options to child_process.fork. See nodejs documentation for available options.
  • workerOpts: Object. For web worker type. An object passed to the constructor of the web worker. See WorkerOptions specification for available options.
  • workerThreadOpts: Object. For worker worker type. An object passed to worker_threads.options. See nodejs documentation for available options.
  • onCreateWorker: Function. A callback that is called whenever a worker is being created. It can be used to allocate resources for each worker for example. The callback is passed as argument an object with the following properties:
    • forkArgs: String[]: the forkArgs option of this pool
    • forkOpts: Object: the forkOpts option of this pool
    • workerOpts: Object: the workerOpts option of this pool
    • script: string: the script option of this pool Optionally, this callback can return an object containing one or more of the above properties. The provided properties will be used to override the Pool properties for the worker being created.
  • onTerminateWorker: Function. A callback that is called whenever a worker is being terminated. It can be used to release resources that might have been allocated for this specific worker. The callback is passed as argument an object as described for onCreateWorker, with each property sets with the value for the worker being terminated.
  • emitStdStreams: boolean. For process or thread worker type. If true, the worker will emit stdout and stderr events instead of passing it through to the parent streams. Default value is false.

Important note on 'workerType': when sending and receiving primitive data types (plain JSON) from and to a worker, the different worker types ('web', 'process', 'thread') can be used interchangeably. However, when using more advanced data types like buffers, the API and returned results can vary. In these cases, it is best not to use the 'auto' setting but have a fixed 'workerType' and good unit testing in place.

A worker pool contains the following functions:

  • Pool.exec(method: Function | string, params: Array | null [, options: Object]) : Promise<any, Error>
    Execute a function on a worker with given arguments.

    • When method is a string, a method with this name must exist at the worker and must be registered to make it accessible via the pool. The function will be executed on the worker with given parameters.
    • When method is a function, the provided function fn will be stringified, send to the worker, and executed there with the provided parameters. The provided function must be static, it must not depend on variables in a surrounding scope.
    • The following options are available:
      • on: (payload: any) => void. An event listener, to handle events sent by the worker for this execution. See Events for more details.
      • transfer: Object[]. A list of transferable objects to send to the worker. Not supported by process worker type. See example for usage.
  • Pool.proxy() : Promise<Object, Error>
    Create a proxy for the worker pool. The proxy contains a proxy for all methods available on the worker. All methods return promises resolving the methods result.

  • Pool.stats() : Object
    Retrieve statistics on workers, and active and pending tasks.

    Returns an object containing the following properties:

    {
      totalWorkers: 0,
      busyWorkers: 0,
      idleWorkers: 0,
      pendingTasks: 0,
      activeTasks: 0
    }
  • Pool.terminate([force: boolean [, timeout: number]]) : Promise<void, Error>

    If parameter force is false (default), workers will finish the tasks they are working on before terminating themselves. Any pending tasks will be rejected with an error 'Pool terminated'. When force is true, all workers are terminated immediately without finishing running tasks. If timeout is provided, worker will be forced to terminate when the timeout expires and the worker has not finished.

The function Pool.exec and the proxy functions all return a Promise. The promise has the following functions available:

  • Promise.then(fn: Function<result: any>) : Promise<any, Error>
    Get the result of the promise once resolve.
  • Promise.catch(fn: Function<error: Error>) : Promise<any, Error>
    Get the error of the promise when rejected.
  • Promise.finally(fn: Function<void>)
    Logic to run when the Promise either resolves or rejects
  • Promise.cancel() : Promise<any, Error>
    A running task can be cancelled. The worker executing the task is enforced to terminate immediately. The promise will be rejected with a Promise.CancellationError.
  • Promise.timeout(delay: number) : Promise<any, Error>
    Cancel a running task when it is not resolved or rejected within given delay in milliseconds. The timer will start when the task is actually started, not when the task is created and queued. The worker executing the task is enforced to terminate immediately. The promise will be rejected with a Promise.TimeoutError.

Example usage:

const workerpool = require('workerpool');

function add(a, b) {
  return a + b;
}

const pool1 = workerpool.pool();

// offload a function to a worker
pool1
  .exec(add, [2, 4])
  .then(function (result) {
    console.log(result); // will output 6
  })
  .catch(function (err) {
    console.error(err);
  });

// create a dedicated worker
const pool2 = workerpool.pool(__dirname + '/myWorker.js');

// supposed myWorker.js contains a function 'fibonacci'
pool2
  .exec('fibonacci', [10])
  .then(function (result) {
    console.log(result); // will output 55
  })
  .catch(function (err) {
    console.error(err);
  });

// send a transferable object to the worker
// supposed myWorker.js contains a function 'sum'
const toTransfer = new Uint8Array(2).map((_v, i) => i)
pool2
  .exec('sum', [toTransfer], { transfer: [toTransfer.buffer] })
  .then(function (result) {
    console.log(result); // will output 3
  })
  .catch(function (err) {
    console.error(err);
  });

// create a proxy to myWorker.js
pool2
  .proxy()
  .then(function (myWorker) {
    return myWorker.fibonacci(10);
  })
  .then(function (result) {
    console.log(result); // will output 55
  })
  .catch(function (err) {
    console.error(err);
  });

// create a pool with a specified maximum number of workers
const pool3 = workerpool.pool({ maxWorkers: 7 });

worker

A worker is constructed as:

workerpool.worker([methods: Object<String, Function>] [, options: Object]) : void

Argument methods is optional and can be an object with functions available in the worker. Registered functions will be available via the worker pool.

The following options are available:

  • onTerminate: ([code: number]) => Promise<void> | void. A callback that is called whenever a worker is being terminated. It can be used to release resources that might have been allocated for this specific worker. The difference with pool's onTerminateWorker is that this callback runs in the worker context, while onTerminateWorker is executed on the main thread.

Example usage:

// file myWorker.js
const workerpool = require('workerpool');

function add(a, b) {
  return a + b;
}

function multiply(a, b) {
  return a * b;
}

// create a worker and register functions
workerpool.worker({
  add: add,
  multiply: multiply,
});

Asynchronous results can be handled by returning a Promise from a function in the worker:

// file myWorker.js
const workerpool = require('workerpool');

function timeout(delay) {
  return new Promise(function (resolve, reject) {
    setTimeout(resolve, delay);
  });
}

// create a worker and register functions
workerpool.worker({
  timeout: timeout,
});

Transferable objects can be sent back to the pool using Transfer helper class:

// file myWorker.js
const workerpool = require('workerpool');

function array(size) {
  var array = new Uint8Array(size).map((_v, i) => i);
  return new workerpool.Transfer(array, [array.buffer]);
}

// create a worker and register functions
workerpool.worker({
  array: array,
});

Tasks may configure an abort handler to perform cleanup operations when timeout or cancel is called on a task. the abortListenerTimeout option can be configured to control when cleanup should be aborted in the case an abortHandler never resolves. This timeout trigger will cause the given worker to be cleaned up. Allowing a new worker to be created if need be.

function asyncTimeout() {
  var me = this;
  return new Promise(function (resolve) {
    let timeout = setTimeout(() => {
        resolve();
    }, 5000); 

    // An abort listener allows for cleanup for a given worker
    // such that it may be resused for future tasks
    // if an execption is thrown within scope of the handler
    // the worker instance will be destroyed.
    me.worker.addAbortListener(async function () {
        clearTimeout(timeout);
        resolve();
    });
  });
}

// create a worker and register public functions
workerpool.worker(
  {
    asyncTimeout: asyncTimeout,
  },
  {
    abortListenerTimeout: 1000
  }
);

Events

You can send data back from workers to the pool while the task is being executed using the workerEmit function:

workerEmit(payload: any) : unknown

This function only works inside a worker and during a task.

Example:

// file myWorker.js
const workerpool = require('workerpool');

function eventExample(delay) {
  workerpool.workerEmit({
    status: 'in_progress',
  });

  workerpool.workerEmit({
    status: 'complete',
  });

  return true;
}

// create a worker and register functions
workerpool.worker({
  eventExample: eventExample,
});

To receive those events, you can use the on option of the pool exec method:

pool.exec('eventExample', [], {
  on: function (payload) {
    if (payload.status === 'in_progress') {
      console.log('In progress...');
    } else if (payload.status === 'complete') {
      console.log('Done!');
    }
  },
});

Utilities

Following properties are available for convenience:

  • platform: The Javascript platform. Either node or browser
  • isMainThread: Whether the code is running in main thread or not (Workers)
  • cpus: The number of CPUs/cores available

Roadmap

  • Implement functions for parallel processing: map, reduce, forEach, filter, some, every, ...
  • Implement graceful degradation on old browsers not supporting webworkers: fallback to processing tasks in the main application.
  • Implement session support: be able to handle a series of related tasks by a single worker, which can keep a state for the session.

Build

First clone the project from github:

git clone git://github.com/josdejong/workerpool.git
cd workerpool

Install the project dependencies:

npm install

Then, the project can be build by executing the build script via npm:

npm run build

This will build the library workerpool.js and workerpool.min.js from the source files and put them in the folder dist.

Test

To execute tests for the library, install the project dependencies once:

npm install

Then, the tests can be executed:

npm test

To test code coverage of the tests:

npm run coverage

To see the coverage results, open the generated report in your browser:

./coverage/index.html

Publish

  • Describe changes in HISTORY.md.
  • Update version in package.json, run npm install to update it in package-lock.json too.
  • Push to GitHub.
  • Deploy to npm via npm publish.
  • Add a git tag with the version number like:
    git tag v1.2.3
    git push --tags

License

Copyright (C) 2014-2024 Jos de Jong wjosdejong@gmail.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

changelog

workerpool history

https://github.com/josdejong/workerpool

2024-10-11, version 9.2.0

  • Feat: implement support for abort handlers in the workers (#448). Thanks @joshLong145.
  • Feat: implement Promise.finally() on the custom promise class (#388). Thanks @joshLong145 and @wmertens.
  • Fix #460: vite example not working (#461). Thanks @datashaman.

2024-06-28, version 9.1.3

  • Fix transferring from the worker (#455). Thanks @LeonidPolukhin.

2024-06-04, version 9.1.2

  • Fix: #446 ensure the library can be used with older browsers.

2024-04-06, version 9.1.1

  • Fix: events not emitted when using (#439). Thanks @t0oF-azpn.

2024-01-18, version 9.1.0

  • Support capturing the stdout/stderr streams from the workers (#425, #423). Thanks @cpendery.

2023-12-22, version 9.0.4

  • Improve the logic to detect the Node.js platform (#421). Thanks @tamuratak.

2023-12-20, version 9.0.3

  • Improve types: unwrap Promise types (#419). Thanks @joshkel.

2023-12-19, version 9.0.2

  • Export the Proxy type (see #417). Thanks @tamuratak.
  • Use workerpool's Promise type definition (see #417). Thanks @tamuratak.

2023-12-18, version 9.0.1

  • Export the types Pool, WorkerPoolOptions, and WorkerRegisterOptions, see #416. Thanks @joshkel.

2023-12-18, version 9.0.0

BREAKING CHANGE: the library now comes with TypeScript type definitions included. There may be minor differences between the new, embedded type definitions and the implementation from @types/workerpool that was needed before. For example, type WorkerPool is called type Pool now.

  • Generate TypeScript types from JSDoc comments. Thanks @tamuratak.

2023-10-25, version 8.0.0

BREAKING CHANGE: the library now throws an Error when passing unknown or inherited properties for workerOpts, workerThreadOpts and forkOpts.

  • Fix: throw an error in case of unknown properties or inherited properties in workerOpts, workerThreadOpts and forkOpts to protect against security issues related to prototype pollution (see ea5368c5e53d97120b952ffad151a318c1ff073c).
  • Fix: #56 document the return type of all functions.
  • Docs: added a full usage example with Vite and Webpack5 (#408), thanks @KonghaYao.

2023-10-25, version 7.0.0

BREAKING CHANGE: The setup to bundle workerpool has been replaced. This should be a drop-in replacement, but it may have impact depending on your setup.

  • Switched build setup from Webpack to Rollup, see #403. Thanks @KonghaYao.

2023-10-11, version 6.5.1

  • Fix: workerThreadOpts not working when workerType: auto, see #357.

2023-09-13, version 6.5.0

  • Implement support for passing options to web workers constructors (#400,

    322). Thanks @DonatJR.

2023-08-21, version 6.4.2

  • Fix: a bug in the timeout of termination (#395, #387). Thanks @Michsior14.

2023-08-17, version 6.4.1

  • Fix: worker termination before it's ready (#394, #387). Thanks @Michsior14.

2023-02-24, version 6.4.0

  • Support transferable objects (#3, #374). Thanks @Michsior14.
  • Implement a new callback onTerminate at the worker side, which can be used to clean up resources, and an option workerTerminateTimeout which forcefully terminates a worker if it doesn't finish in time (#353, #377). Thanks @Michsior14.
  • Pass workerThreadOpts to the onTerminateWorker callback (#376). Thanks @Michsior14.

2022-11-07, version 6.3.1

  • Fix #318: debug ports not being released when terminating a pool.

2022-10-24, version 6.3.0

  • Implement option workerThreadOpts to pass options to a worker of type thread, a worker_thread (#357, fixes #356). Thanks @galElmalah.

2022-04-11, version 6.2.1

  • Fix #343: .terminate() sometimes throwing an exception.

2022-01-15, version 6.2.0

  • Implement callbacks onCreateWorker and onTerminateWorker. Thanks @forty.
  • Fix #326: robustness fix when terminating a workerpool.

2021-06-17, version 6.1.5

  • Fix v6.1.4 not being marked as latest anymore on npm due to bug fix release v2.3.4.

2021-04-05, version 6.1.4

  • Fix terminating a pool throwing an error when used in the browser. Regression introduced in v6.1.3.

2021-04-01, version 6.1.3

  • Fix #147: disregard messages from terminated workers. Thanks @hhprogram and @Madgvox.

2021-03-09, version 6.1.2

  • Fix #253, add ./src again in the published npm package, reverting the change in v6.1.1 (see also #243).

2021-03-08, version 6.1.1

  • Remove redundant ./src folder from the published npm package, see #243. Thanks @Nytelife26.

2021-01-31, version 6.1.0

  • Implemented support for sending events from the worker to the main thread, see #51, #227. Thanks @Akryum.
  • Fix an issue in Node.js nightly, see #230. Thanks @aduh95.
  • Fix #232 workerpool not working on IE 10.

2021-01-16, version 6.0.4

  • Make evaluation of offloaded functions a bit more secure by using new Function instead of eval. Thanks @tjenkinson.

2020-10-28, version 6.0.3

  • Fixes and more robustness in terminating workers. Thanks @boneskull.

2020-10-03, version 6.0.2

  • Fix #32, #175: the promise returned by Pool.terminate() now waits until subprocesses are dead before resolving. Thanks @boneskull.

2020-09-23, version 6.0.1

  • Removed examples from the npm package. Thanks @madbence.

2020-05-13, version 6.0.0

BREAKING CHANGE: the library entry points are changed and new source maps are added. This may have impact on your project depending on your setup.

  • Created separate library entry points in package.json for node.js and browser. Thanks @boneskull.
  • Generated source maps for both minified and non-minified bundles.
  • Removed deprecation warnings for options.nodeWorker (renamed to options.workerType) and pool.clear() (renamed to pool.terminate()).

2019-12-31, version 5.0.4

  • Fixed #121: isMainThread not working when using worker_threads.
  • Drop official support for node.js 8 (end of life).

2019-12-23, version 5.0.3

  • Fixed library not working in the browser. See #106.

2019-11-06, version 5.0.2

  • Fixed environment detection in browser. See #106. Thanks @acgrid.

2019-10-13, version 5.0.1

  • Fixed #96: WorkerPool not cancelling any pending tasks on termination.

2019-08-25, version 5.0.0

  • Deprecated option nodeWorker and created a new, more extensive option workerType giving full control over the selected type of worker. Added new option 'web' to enforce use a Web Worker. See #85, #74.
  • In a node.js environment, the default workerType is changed from 'process' to 'thread'. See #85, #50.
  • Improved detection of environment (browser or node), fixing wrong detection in a Jest test environment. See #85.

2019-08-21, version 4.0.0

  • Pass argument --max-old-space-size to child processes. Thanks @patte.
  • Removed redundant dependencies, upgraded all devDependencies.
  • Fixed Webpack issues of missing modules child_process and worker_threads. See #43.
  • Bundled library changed due to the upgrade to Webpack 4. This could possibly lead to breaking changes.
  • Implemented new option maxQueueSize. Thanks @colomboe.
  • Fixed exiting workers when the parent process is killed. Thanks @RogerKang.
  • Fixed #81: Option minWorkers: 'max' not using the configured maxWorkers.
  • Fixed not passing nodeWorker to workers initialized when creating a pool. Thanks @spacelan.
  • Internal restructure of the code: moved from lib to src.

2019-03-12, version 3.1.2

  • Improved error message when a node.js worker unexpectedly exits (see #58). Thanks @stefanpenner.

  • Allocate debug ports safely, this fixes an issue cause workers to exit unexpectedly if more then one worker pool is active, and the process is started with a debugger (node debug or node --inspect). Thanks @stefanpenner.

2019-02-25, version 3.1.1

  • Fix option nodeWorker: 'auto' not using worker threads when available. Thanks @stefanpenner.

2019-02-17, version 3.1.0

  • Implemented support for using worker_threads in Node.js, via the new option nodeWorker: 'thread'. Thanks @stefanpenner.

2018-12-11, version 3.0.0

  • Enable usage in ES6 Webpack projects.
  • Dropped support for AMD module system.

2021-06-17, version 2.3.4

  • Backport fix for Node.js 16, see #309. Thanks @mansona.

2018-09-12, version 2.3.3

  • Fixed space in license field in package.json. Thanks @sagotsky.

2018-09-08, version 2.3.2

  • Add licence field to package.json. Thanks @greyd.

2018-07-24, version 2.3.1

  • Fixed bug where tasks that are cancelled in a Pool's queue causes following tasks to not run. Thanks @greemo.

2017-09-30, version 2.3.0

  • New method Pool.terminate(force, timeout) which will replace Pool.clear(force). Thanks @jimsugg.
  • Fixed issue with never terminating zombie child processes. Thanks @jimsugg.

2017-08-20, version 2.2.4

  • Fixed a debug issue: look for --inspect within argument strings, instead of exact match. Thanks @jimsugg.

2017-08-19, version 2.2.3

  • Updated all examples to neatly include .catch(...) callbacks.

2017-07-08, version 2.2.2

  • Fixed #25: timer of a timeout starting when the task is created instead of when the task is started. Thanks @eclipsesk for input.

2017-05-07, version 2.2.1

  • Fixed #2 and #19: support for debugging child processes. Thanks @tptee.

2016-11-26, version 2.2.0

  • Implemented #18: method pool.stats().

2016-10-11, version 2.1.0

  • Implemented support for registering the workers methods asynchronously. This enables asynchronous initialization of workers, for example when using AMD modules. Thanks @natlibfi-arlehiko.
  • Implemented environment variables platform, isMainThread, and cpus. Thanks @natlibfi-arlehiko.
  • Implemented option minWorkers. Thanks @sergei202.

2016-09-18, version 2.0.0

  • Replaced conversion of Error-objecting using serializerr to custom implementation to prevent issues with serializing/deserializing functions. This conversion implementation loses the prototype object which means that e.g. 'TypeError' will become just 'Error' in the main code. See #8. Thanks @natlibfi-arlehiko.

2016-09-12, version 1.3.1

  • Fix for a bug in PhantomJS (see #7). Thanks @natlibfi-arlehiko.

2016-08-21, version 1.3.0

  • Determine maxWorkers as the number of CPU's minus one in browsers too. See #6.

2016-06-25, version 1.2.1

  • Fixed #5 error when loading via AMD or bundling using Webpack.

2016-05-22, version 1.2.0

  • Implemented serializing errors with stacktrace. Thanks @mujx.

2016-01-25, version 1.1.0

  • Added an error message when wrongly calling pool.proxy.
  • Fixed function worker.pool not accepting both a script and options. See #1. Thanks @freund17.

2014-05-29, version 1.0.0

  • Merged function Pool.run into Pool.exec, simplifying the API.

2014-05-14, version 0.2.0

  • Implemented support for cancelling running tasks.
  • Implemented support for cancelling running tasks after a timeout.

2014-05-07, version 0.1.0

  • Implemented support for both node.js and the browser.
  • Implemented offloading functions.
  • Implemented worker proxy.
  • Added docs and examples.

2014-05-02, version 0.0.1

  • Module name registered at npm.