Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 885 Bytes

README.md

File metadata and controls

28 lines (23 loc) · 885 Bytes

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 */);
});