@davvo/worker-pool

Distribute work in node.js

Usage no npm install needed!

<script type="module">
  import davvoWorkerPool from 'https://cdn.skypack.dev/@davvo/worker-pool';
</script>

README

worker-pool

Distribute work in node.js

Install

> npm install @davvo/worker-pool

Example

// adder.js
var pool = require('@davvo/worker-pool');

pool.handleSync(function (params) { 
  return params.a + params.b;
});
// main.js
var pool = require('@davvo/worker-pool')({
  worker: 'adder.js'
});

pool.doWork({a: 28, b: 14}).then(function (sum) {
  console.log("The answer is", sum);
});

Async workers

pool.handle(function (params, callback) {
  callback(null, params.a + param.b);
});

Pool options

var pool = require('@davvo/worker-pool')({
  worker: __dirname + '/my-worker.js',
  numWorkers: 2
  timeout: 5000
});