3 isMainThread
, parentPort
4 } = require('worker_threads')
7 * An example worker that will be always alive, you just need to extend this class if you want a static pool.
8 * @author Alessandro Pio Ardizio
13 if (!fn
) throw new Error('Fn parameter is mandatory')
14 // keep the worker active
20 parentPort
.on('message', (value
) => {
22 // save the port to communicate with the main thread
23 this.parent
= value
.parent
24 } else if (value
&& value
._id
) {
25 // console.log('This is the main thread ' + isMainThread)
26 this.parent
.postMessage({ data
: fn(value
), _id
: value
._id
})
32 module
.exports
= ThreadWorker