import type EventEmitterAsyncResource from 'node:events';
import fs from 'node:fs';
+import type { PoolInfo } from 'poolifier';
+
import { WorkerConstants } from './WorkerConstants';
-import type { WorkerData, WorkerOptions } from './WorkerTypes';
+import type { SetInfo, WorkerData, WorkerOptions } from './WorkerTypes';
export abstract class WorkerAbstract<T extends WorkerData> {
protected readonly workerScript: string;
protected readonly workerOptions: WorkerOptions;
+ public abstract readonly info: PoolInfo | SetInfo;
public abstract readonly size: number;
public abstract readonly maxElementsPerWorker: number | undefined;
public abstract readonly emitter: EventEmitterAsyncResource | undefined;
import type EventEmitterAsyncResource from 'node:events';
import type { Worker } from 'node:worker_threads';
-import { DynamicThreadPool, type ErrorHandler, type ExitHandler } from 'poolifier';
+import { DynamicThreadPool, type ErrorHandler, type ExitHandler, type PoolInfo } from 'poolifier';
import { WorkerAbstract } from './WorkerAbstract';
import type { WorkerData, WorkerOptions } from './WorkerTypes';
);
}
+ get info(): PoolInfo {
+ return this.pool.info;
+ }
+
get size(): number {
- return this.pool.workerNodes.length;
+ return this.pool.info.workerNodes;
}
get maxElementsPerWorker(): number | undefined {
import { WorkerConstants } from './WorkerConstants';
import {
type MessageHandler,
+ type SetInfo,
type WorkerData,
WorkerMessageEvents,
type WorkerOptions,
this.emitter = new EventEmitterAsyncResource();
}
+ get info(): SetInfo {
+ return {
+ size: this.size,
+ runningElements: [...this.workerSet].reduce(
+ (accumulator, workerSetElement) => accumulator + workerSetElement.numberOfWorkerElements,
+ 0
+ ),
+ elementsPerWorker: this.maxElementsPerWorker,
+ };
+ }
+
get size(): number {
return this.workerSet.size;
}
import type EventEmitterAsyncResource from 'node:events';
import type { Worker } from 'node:worker_threads';
-import { type ErrorHandler, type ExitHandler, FixedThreadPool } from 'poolifier';
+import { type ErrorHandler, type ExitHandler, FixedThreadPool, type PoolInfo } from 'poolifier';
import { WorkerAbstract } from './WorkerAbstract';
import type { WorkerData, WorkerOptions } from './WorkerTypes';
);
}
+ get info(): PoolInfo {
+ return this.pool.info;
+ }
+
get size(): number {
- return this.pool.workerNodes.length;
+ return this.pool.info.workerNodes;
}
get maxElementsPerWorker(): number | undefined {
staticPool = 'staticPool',
}
+export type SetInfo = {
+ size: number;
+ runningElements: number;
+ elementsPerWorker: number;
+};
+
export type MessageHandler<T> = (this: T, message: unknown) => void;
export type WorkerOptions = {