repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build: cleanup eslint configuration
[e-mobility-charging-stations-simulator.git]
/
src
/
worker
/
WorkerSet.ts
diff --git
a/src/worker/WorkerSet.ts
b/src/worker/WorkerSet.ts
index 7f140527d365bf12dd5b985e3d8c2c583a10de3f..17b5b6dde201c85f4c0af0cbaf3574d33968fb03 100644
(file)
--- a/
src/worker/WorkerSet.ts
+++ b/
src/worker/WorkerSet.ts
@@
-1,6
+1,6
@@
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import { EventEmitter } from 'node:events';
+import { EventEmitter
AsyncResource
} from 'node:events';
import { SHARE_ENV, Worker } from 'node:worker_threads';
import { WorkerAbstract } from './WorkerAbstract';
import { SHARE_ENV, Worker } from 'node:worker_threads';
import { WorkerAbstract } from './WorkerAbstract';
@@
-17,7
+17,7
@@
import {
import { randomizeDelay, sleep } from './WorkerUtils';
export class WorkerSet extends WorkerAbstract<WorkerData> {
import { randomizeDelay, sleep } from './WorkerUtils';
export class WorkerSet extends WorkerAbstract<WorkerData> {
- public readonly emitter
!: EventEmitter
;
+ public readonly emitter
: EventEmitterAsyncResource | undefined
;
private readonly workerSet: Set<WorkerSetElement>;
private started: boolean;
private workerStartup: boolean;
private readonly workerSet: Set<WorkerSetElement>;
private started: boolean;
private workerStartup: boolean;
@@
-44,7
+44,7
@@
export class WorkerSet extends WorkerAbstract<WorkerData> {
}
this.workerSet = new Set<WorkerSetElement>();
if (this.workerOptions.poolOptions?.enableEvents) {
}
this.workerSet = new Set<WorkerSetElement>();
if (this.workerOptions.poolOptions?.enableEvents) {
- this.emitter = new EventEmitter
(
);
+ this.emitter = new EventEmitter
AsyncResource({ name: 'workerset' }
);
}
this.started = false;
this.workerStartup = false;
}
this.started = false;
this.workerStartup = false;
@@
-78,6
+78,7
@@
export class WorkerSet extends WorkerAbstract<WorkerData> {
// Add worker set element sequentially to optimize memory at startup
this.workerOptions.workerStartDelay! > 0 &&
(await sleep(randomizeDelay(this.workerOptions.workerStartDelay!)));
// Add worker set element sequentially to optimize memory at startup
this.workerOptions.workerStartDelay! > 0 &&
(await sleep(randomizeDelay(this.workerOptions.workerStartDelay!)));
+ this.emitter?.emit(WorkerSetEvents.started, this.info);
this.started = true;
}
this.started = true;
}
@@
-92,6
+93,9
@@
export class WorkerSet extends WorkerAbstract<WorkerData> {
});
await worker.terminate();
await waitWorkerExit;
});
await worker.terminate();
await waitWorkerExit;
+ this.emitter?.emit(WorkerSetEvents.stopped, this.info);
+ this.emitter?.emitDestroy();
+ this.emitter?.removeAllListeners();
this.started = false;
}
}
this.started = false;
}
}
@@
-101,7
+105,7
@@
export class WorkerSet extends WorkerAbstract<WorkerData> {
if (!this.started) {
throw new Error('Cannot add a WorkerSet element: not started');
}
if (!this.started) {
throw new Error('Cannot add a WorkerSet element: not started');
}
- if (
!this.workerSet
) {
+ if (
this.workerSet == null
) {
throw new Error("Cannot add a WorkerSet element: 'workerSet' property does not exist");
}
const workerSetElement = await this.getWorkerSetElement();
throw new Error("Cannot add a WorkerSet element: 'workerSet' property does not exist");
}
const workerSetElement = await this.getWorkerSetElement();