WorkerMessageEvents,
type WorkerOptions,
type WorkerSetElement,
+ WorkerSetEvents,
} from './WorkerTypes';
import { defaultErrorHandler, defaultExitHandler, sleep } from './WorkerUtils';
);
worker.on('error', defaultErrorHandler.bind(this) as (err: Error) => void);
worker.on('error', (error) => {
- this.emitter.emit('error', error);
+ this.emitter.emit(WorkerSetEvents.error, error);
this.addWorkerSetElement();
});
worker.on('exit', defaultExitHandler.bind(this) as (exitCode: number) => void);
import type { Worker } from 'node:worker_threads';
-import type { PoolOptions } from 'poolifier';
+import { type PoolEvent, PoolEvents, type PoolOptions } from 'poolifier';
export enum WorkerProcessType {
workerSet = 'workerSet',
elementsPerWorker: number;
};
+export enum WorkerSetEvents {
+ error = 'error',
+}
+
+export const WorkerEvents = {
+ ...PoolEvents,
+ ...WorkerSetEvents,
+} as const;
+export type WorkerEvents = PoolEvent | WorkerSetEvents;
+
export type MessageHandler<T> = (this: T, message: unknown) => void;
export type WorkerOptions = {