export class WorkerSet extends WorkerAbstract<WorkerData> {
public readonly emitter!: EventEmitter;
private readonly workerSet: Set<WorkerSetElement>;
+ private workerStartup: boolean;
/**
* Creates a new `WorkerSet`.
if (this.workerOptions.poolOptions?.enableEvents) {
this.emitter = new EventEmitter();
}
+ this.workerStartup = false;
}
get info(): SetInfo {
* Adds a new `WorkerSetElement`.
*/
private addWorkerSetElement(): WorkerSetElement {
+ this.workerStartup = true;
const worker = new Worker(this.workerScript, {
env: SHARE_ENV,
...this.workerOptions.poolOptions?.workerOptions,
worker.on('error', this.workerOptions.poolOptions?.errorHandler ?? EMPTY_FUNCTION);
worker.on('error', (error) => {
this.emitter?.emit(WorkerSetEvents.error, error);
- if (this.workerOptions.poolOptions?.restartWorkerOnError) {
+ if (this.workerOptions.poolOptions?.restartWorkerOnError && !this.workerStartup) {
this.addWorkerSetElement();
}
});
worker.once('exit', () =>
this.removeWorkerSetElement(this.getWorkerSetElementByWorker(worker)!),
);
+ this.workerStartup = false;
const workerSetElement: WorkerSetElement = { worker, numberOfWorkerElements: 0 };
this.workerSet.add(workerSetElement);
return workerSetElement;