- // Start worker sequentially to optimize memory at startup
- await Utils.sleep(Constants.START_WORKER_DELAY);
- }
-}
-
-class StaticPool extends FixedThreadPool<WorkerData> {
- private static instance: StaticPool;
-
- private constructor(numThreads: number, workerScript: string, opts?: FixedThreadPoolOptions) {
- super(numThreads, workerScript, opts);
- }
-
- 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;
+ // Start element sequentially to optimize memory at startup
+ this.workerOptions.elementStartDelay > 0 &&
+ (await Utils.sleep(this.workerOptions.elementStartDelay));