- public static getInstance(numThreads: number, workerScript: string): StaticPool {
- if (!StaticPool.instance) {
- StaticPool.instance = new StaticPool(numThreads, workerScript,
- {
- exitHandler: (code) => {
- if (code !== 0) {
- console.error(`Worker stopped with exit code ${code}`);
- }
- }
- }
- );
- }
- return StaticPool.instance;
+ /** @inheritDoc */
+ 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!));