From: Jérôme Benoit Date: Mon, 11 Dec 2023 12:26:46 +0000 (+0100) Subject: perf: a worker is not an AsyncResource X-Git-Tag: v3.0.11~7 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=69b70a7e1d5238ebb186171275941ec4bcffc882;p=poolifier.git perf: a worker is not an AsyncResource Signed-off-by: Jérôme Benoit --- diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 060fe634..5fcc3419 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -1,4 +1,3 @@ -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' @@ -56,7 +55,7 @@ export abstract class AbstractWorker< MainWorker extends Worker | MessagePort, Data = unknown, Response = unknown -> extends AsyncResource { +> { /** * Worker id. */ @@ -93,7 +92,7 @@ export abstract class AbstractWorker< taskFunctions: TaskFunction | TaskFunctions, protected opts: WorkerOptions = DEFAULT_WORKER_OPTIONS ) { - super(type) + // super(type) if (this.isMain == null) { throw new Error('isMain parameter is mandatory') } @@ -379,10 +378,6 @@ export abstract class AbstractWorker< .catch(() => { this.sendToMainWorker({ kill: 'failure' }) }) - .finally(() => { - this.emitDestroy() - }) - .catch(EMPTY_FUNCTION) } else { try { // eslint-disable-next-line @typescript-eslint/no-invalid-void-type @@ -390,8 +385,6 @@ export abstract class AbstractWorker< this.sendToMainWorker({ kill: 'success' }) } catch { this.sendToMainWorker({ kill: 'failure' }) - } finally { - this.emitDestroy() } } } @@ -507,9 +500,9 @@ export abstract class AbstractWorker< } const fn = this.taskFunctions.get(taskFunctionName) if (isAsyncFunction(fn)) { - this.runInAsyncScope(this.runAsync.bind(this), this, fn, task) + this.runAsync(fn as TaskAsyncFunction, task) } else { - this.runInAsyncScope(this.runSync.bind(this), this, fn, task) + this.runSync(fn as TaskSyncFunction, task) } }