-import { AsyncResource } from 'node:async_hooks'
import type { Worker } from 'node:cluster'
import type { MessagePort } from 'node:worker_threads'
import { performance } from 'node:perf_hooks'
MainWorker extends Worker | MessagePort,
Data = unknown,
Response = unknown
-> extends AsyncResource {
+> {
/**
* Worker id.
*/
taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>,
protected opts: WorkerOptions = DEFAULT_WORKER_OPTIONS
) {
- super(type)
+ // super(type)
if (this.isMain == null) {
throw new Error('isMain parameter is mandatory')
}
.catch(() => {
this.sendToMainWorker({ kill: 'failure' })
})
- .finally(() => {
- this.emitDestroy()
- })
- .catch(EMPTY_FUNCTION)
} else {
try {
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
this.sendToMainWorker({ kill: 'success' })
} catch {
this.sendToMainWorker({ kill: 'failure' })
- } finally {
- this.emitDestroy()
}
}
}
}
const fn = this.taskFunctions.get(taskFunctionName)
if (isAsyncFunction(fn)) {
- this.runInAsyncScope(this.runAsync.bind(this), this, fn, task)
+ this.runAsync(fn as TaskAsyncFunction<Data, Response>, task)
} else {
- this.runInAsyncScope(this.runSync.bind(this), this, fn, task)
+ this.runSync(fn as TaskSyncFunction<Data, Response>, task)
}
}