Appolo Thread
Thread Pool using node worker_threads
Installation
npm install appolo-thread --save
Usage
;
worker class, must inherit Worker
;
Api
Pool options:
path
- path to worker classthreads
- number of threads to runworkerData
- custom worker data object will be passed to worker constructor
const pool = path:'./workers/fibonacci.js' threads: 2 workerData :some:"value";
Initialize
initialize the pool return promise when completed
const pool = path:'./workers/fibonacci.js' threads: 2; await pool;
you can also implement worker initialize method.
the method will be called on pool initialize
;
Run
run worker with custom params. return promise with the worker result
const pool = path:'./workers/fibonacci.js' threads: 2; await pool; let reuslt = await pool
Message event
The message
event is emitted from the worker using the worker postMessage
method
const pool = path:'./workers/fibonacci.js' threads: 2; await pool; pool
post message in worker class
;
Uncaught event
The error
event is emitted if the worker thread throws an uncaught exception.
const pool = path:'./workers/fibonacci.js' threads: 2; await pool; pool
License
MIT