From: Jérôme Benoit Date: Mon, 10 Apr 2023 11:41:53 +0000 (+0200) Subject: refactor: enforce more worker type safety X-Git-Tag: v2.4.7~21 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=50e66724ecb17b83dfb87b1128ca9674f9b14e03;p=poolifier.git refactor: enforce more worker type safety Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 3c660031..f24d79e4 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -2,6 +2,7 @@ import EventEmitter from 'node:events' import type { ErrorHandler, ExitHandler, + IWorker, MessageHandler, OnlineHandler } from './worker' @@ -31,7 +32,7 @@ export type PoolEvent = keyof typeof PoolEvents /** * Options for a poolifier pool. */ -export interface PoolOptions { +export interface PoolOptions { /** * A function that will listen for message event on each worker. */ diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 4ff2c494..1e23ee87 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -3,22 +3,31 @@ import type { CircularArray } from '../circular-array' /** * Callback invoked if the worker has received a message. */ -export type MessageHandler = (this: Worker, m: unknown) => void +export type MessageHandler = ( + this: Worker, + m: unknown +) => void /** * Callback invoked if the worker raised an error. */ -export type ErrorHandler = (this: Worker, e: Error) => void +export type ErrorHandler = ( + this: Worker, + e: Error +) => void /** * Callback invoked when the worker has started successfully. */ -export type OnlineHandler = (this: Worker) => void +export type OnlineHandler = (this: Worker) => void /** * Callback invoked when the worker exits successfully. */ -export type ExitHandler = (this: Worker, code: number) => void +export type ExitHandler = ( + this: Worker, + code: number +) => void /** * Worker task interface. diff --git a/src/utility-types.ts b/src/utility-types.ts index b5611f9e..544b4cd0 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -39,6 +39,7 @@ export interface MessageValue< * Reference to main worker. * * Only for internal use. + * @internal */ readonly parent?: MainWorker }