"dev": true
},
"caniuse-lite": {
- "version": "1.0.30001185",
- "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001185.tgz",
- "integrity": "sha512-Fpi4kVNtNvJ15H0F6vwmXtb3tukv3Zg3qhKkOGUq7KJ1J6b9kf4dnNgtEAFXhRsJo0gNj9W60+wBvn0JcTvdTg==",
+ "version": "1.0.30001187",
+ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001187.tgz",
+ "integrity": "sha512-w7/EP1JRZ9552CyrThUnay2RkZ1DXxKe/Q2swTC4+LElLh9RRYrL1Z+27LlakB8kzY0fSmHw9mc7XYDUKAKWMA==",
"dev": true
},
"caseless": {
}
}
+ protected removeWorker (worker: Worker): void {
+ // Clean worker from data structure
+ const workerIndex = this.workers.indexOf(worker)
+ this.workers.splice(workerIndex, 1)
+ this.tasks.delete(worker)
+ }
+
/**
* Execute the task specified into the constructor with the data parameter.
*
if (message.kill) {
this.sendToWorker(worker, { kill: 1 })
void this.destroyWorker(worker)
- // clean workers from data structures
- const workerIndex = this.workers.indexOf(worker)
- this.workers.splice(workerIndex, 1)
- this.tasks.delete(worker)
+ this.removeWorker(worker)
}
})
return worker
protected destroyWorker (worker: Worker): void {
worker.kill()
+ // FIXME: The tests are currently failing, so these must be changed first
}
protected sendToWorker (worker: Worker, message: MessageValue<Data>): void {
if (message.kill) {
this.sendToWorker(worker, { kill: 1 })
void this.destroyWorker(worker)
- // clean workers from data structures
- const workerIndex = this.workers.indexOf(worker)
- this.workers.splice(workerIndex, 1)
- this.tasks.delete(worker)
+ this.removeWorker(worker)
}
})
return worker
worker: ThreadWorkerWithMessageChannel
): Promise<void> {
await worker.terminate()
+ // FIXME: The tests are currently failing, so these must be changed first
}
protected sendToWorker (
this.maxInactiveTime = this.opts.maxInactiveTime ?? 1000 * 60
this.async = !!this.opts.async
this.lastTask = Date.now()
- if (!fn) throw new Error('Fn parameter is mandatory')
+ if (!fn) throw new Error('fn parameter is mandatory')
// keep the worker active
if (!isMain) {
this.interval = setInterval(
worker.on('message', (value: MessageValue<Data>) => {
if (value?.data && value.id) {
// here you will receive messages
- // console.log('This is the main worker ' + isMain)
+ // console.log('This is the main worker ' + isMaster)
if (this.async) {
this.runInAsyncScope(this.runAsync.bind(this), this, fn, value)
} else {
parentPort?.on('message', (value: MessageValue<Data>) => {
if (value?.data && value.id) {
// here you will receive messages
- // console.log('This is the main worker ' + isMain)
+ // console.log('This is the main worker ' + isMainThread)
if (this.async) {
this.runInAsyncScope(this.runAsync.bind(this), this, fn, value)
} else {