X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerSet.ts;h=ce25e7e3a6e4ec3428072a05fc6e13d90e14c0fd;hb=4a3807d16c54137840a60af41877f3b21de12950;hp=61118a0d0a274d17871a71ec8e2ebec3efa2c2a9;hpb=a37fc6dc8267e22b2b2d35773525980b81f014e8;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index 61118a0d..ce25e7e3 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -3,6 +3,8 @@ import { EventEmitter } from 'node:events'; import { SHARE_ENV, Worker } from 'node:worker_threads'; +import type { ThreadPoolOptions } from 'poolifier'; + import { WorkerAbstract } from './WorkerAbstract'; import { WorkerConstants } from './WorkerConstants'; import { @@ -15,6 +17,11 @@ import { } from './WorkerTypes'; import { sleep } from './WorkerUtils'; +const DEFAULT_POOL_OPTIONS: ThreadPoolOptions = { + enableEvents: true, + restartWorkerOnError: true, +}; + export class WorkerSet extends WorkerAbstract { public readonly emitter!: EventEmitter; private readonly workerSet: Set; @@ -25,13 +32,10 @@ export class WorkerSet extends WorkerAbstract { * @param workerScript - * @param workerOptions - */ - constructor(workerScript: string, workerOptions?: WorkerOptions) { + constructor(workerScript: string, workerOptions: WorkerOptions) { super(workerScript, workerOptions); this.workerOptions.poolOptions = { - ...{ - enableEvents: true, - restartWorkerOnError: true, - }, + ...DEFAULT_POOL_OPTIONS, ...this.workerOptions.poolOptions, }; this.workerSet = new Set();