node-threads-pool
Version:
Node-Threads-Pool is a tool for creating thread pools in Node.js, making it easy to implement efficient parallel computing. With Node-Threads-Pool, you can easily create and manage multiple threads, allocate tasks to worker threads in the thread pool, and
26 lines (25 loc) • 596 B
JavaScript
const {parentPort, workerData} = require("worker_threads");
module.exports = class {
constructor(func) {
this.id = workerData.index;
const self = this;
parentPort.on('message', async data => {
try{
const d = await func(data, self);
parentPort.postMessage({
status: 'success',
data: d
});
} catch(err) {
parentPort.postMessage({
status: 'failed',
data: err.stack || err.message || err
});
}
});
this.timer();
}
timer() {
setInterval(()=>{}, 24 * 60 * 60 * 1000);
}
}