-import type EventEmitterAsyncResource from 'node:events';
-
-import { FixedThreadPool, type PoolInfo } from 'poolifier';
+import { FixedThreadPool, type PoolEmitter, type PoolInfo } from 'poolifier';
import { WorkerAbstract } from './WorkerAbstract';
import type { WorkerData, WorkerOptions } from './WorkerTypes';
private readonly pool: FixedThreadPool<WorkerData>;
/**
- * Create a new `WorkerStaticPool`.
+ * Creates a new `WorkerStaticPool`.
*
* @param workerScript -
* @param workerOptions -
*/
- constructor(workerScript: string, workerOptions?: WorkerOptions) {
+ constructor(workerScript: string, workerOptions: WorkerOptions) {
super(workerScript, workerOptions);
this.pool = new FixedThreadPool(
this.workerOptions.poolMaxSize,
this.workerScript,
- this.workerOptions.poolOptions
+ this.workerOptions.poolOptions,
);
}
return undefined;
}
- get emitter(): EventEmitterAsyncResource | undefined {
+ get emitter(): PoolEmitter | undefined {
return this.pool?.emitter;
}
public async addElement(elementData: WorkerData): Promise<void> {
await this.pool.execute(elementData);
// Start element sequentially to optimize memory at startup
- this.workerOptions.elementStartDelay > 0 && (await sleep(this.workerOptions.elementStartDelay));
+ this.workerOptions.elementStartDelay! > 0 &&
+ (await sleep(this.workerOptions.elementStartDelay!));
}
}