X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fpools%2Fworker.ts;h=ee54c6acc3f17216361f3c20b55b61f74376f260;hb=6e8774e94b8baa73696f341baa18f1fa927d2967;hp=7f8148ffcc93db670479a9ce5d7c96b6e576a1d0;hpb=c63a35a04c190989be80f9218d97e0aca739475e;p=poolifier.git diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 7f8148ff..ee54c6ac 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -1,5 +1,6 @@ -import type { MessageChannel, WorkerOptions } from 'node:worker_threads' import type { EventEmitter } from 'node:events' +import type { MessageChannel, WorkerOptions } from 'node:worker_threads' + import type { CircularArray } from '../circular-array.js' import type { Task } from '../utility-types.js' @@ -212,7 +213,7 @@ export interface StrategyData { /** * Worker interface. */ -export interface IWorker { +export interface IWorker extends EventEmitter { /** * Cluster worker id. */ @@ -227,14 +228,20 @@ export interface IWorker { * @param event - The event. * @param handler - The event handler. */ - readonly on: (event: string, handler: EventHandler) => void + readonly on: (event: string, handler: EventHandler) => this /** * Registers once an event handler. * * @param event - The event. * @param handler - The event handler. */ - readonly once: (event: string, handler: EventHandler) => void + readonly once: (event: string, handler: EventHandler) => this + /** + * Calling `unref()` on a worker allows the thread to exit if this is the only + * active handle in the event system. If the worker is already `unref()`ed calling`unref()` again has no effect. + * @since v10.5.0 + */ + readonly unref?: () => void /** * Stop all JavaScript execution in the worker thread as soon as possible. * Returns a Promise for the exit code that is fulfilled when the `'exit' event` is emitted. @@ -388,6 +395,6 @@ export interface IWorkerNode * @internal */ export interface WorkerNodeEventDetail { - workerId: number + workerId?: number workerNodeKey?: number }