resource-pools-worker
v2.0.3
Published
Extension of a built-in 'worker' class for using it as a pooled resource
Downloads
2
Readme
resource-pools-worker
Extension of a built-in 'worker' class for using as a pooled resource with resource-pools package.
note
Pooled workers are supposed to get incoming data to process via an incoming message and return a message with result when done
usage
Setup worker pool:
const {ResourcePool} = require('resource-pools');
const {WorkerResource} = require('resource-pools-worker');
const config = {
constructor: WorkerResource,
arguments: [/* path to worker file */],
maxCount: /* number of maximum pooled workers */
};
const workers = new ResourcePool(config);
Run job:
workers.allocate().then( worker => {
worker.once('message', message => { /* process received data from worker when done */ });
worker.postMessage(/* send data to process to worker */);
});