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
fix: fix worker options argument passing to worker pool/set
[e-mobility-charging-stations-simulator.git]
/
src
/
worker
/
WorkerStaticPool.ts
diff --git
a/src/worker/WorkerStaticPool.ts
b/src/worker/WorkerStaticPool.ts
index 23112a6c566ff0b95f6f07cf48b606332ab1b7fd..473ff3bba41e0a332394f23a313a8040cf554179 100644
(file)
--- a/
src/worker/WorkerStaticPool.ts
+++ b/
src/worker/WorkerStaticPool.ts
@@
-1,25
+1,22
@@
-import
{ FixedThreadPool } from 'poolifier
';
+import
type EventEmitterAsyncResource from 'node:events
';
-import type { WorkerData, WorkerOptions } from '../types/Worker';
-import Utils from '../utils/Utils';
-import WorkerAbstract from './WorkerAbstract';
-import { WorkerUtils } from './WorkerUtils';
+import { FixedThreadPool, type PoolInfo } from 'poolifier';
-export default class WorkerStaticPool extends WorkerAbstract<WorkerData> {
+import { WorkerAbstract } from './WorkerAbstract';
+import type { WorkerData, WorkerOptions } from './WorkerTypes';
+import { sleep } from './WorkerUtils';
+
+export class WorkerStaticPool extends WorkerAbstract<WorkerData> {
private readonly pool: FixedThreadPool<WorkerData>;
/**
* Create a new `WorkerStaticPool`.
*
private readonly pool: FixedThreadPool<WorkerData>;
/**
* Create a new `WorkerStaticPool`.
*
- * @param workerScript
- * @param workerOptions
+ * @param workerScript
-
+ * @param workerOptions
-
*/
constructor(workerScript: string, workerOptions?: WorkerOptions) {
super(workerScript, workerOptions);
*/
constructor(workerScript: string, workerOptions?: WorkerOptions) {
super(workerScript, workerOptions);
- this.workerOptions.poolOptions.errorHandler =
- this.workerOptions?.poolOptions?.errorHandler ?? WorkerUtils.defaultErrorHandler;
- this.workerOptions.poolOptions.exitHandler =
- this.workerOptions?.poolOptions?.exitHandler ?? WorkerUtils.defaultExitHandler;
this.pool = new FixedThreadPool(
this.workerOptions.poolMaxSize,
this.workerScript,
this.pool = new FixedThreadPool(
this.workerOptions.poolMaxSize,
this.workerScript,
@@
-27,42
+24,36
@@
export default class WorkerStaticPool extends WorkerAbstract<WorkerData> {
);
}
);
}
+ get info(): PoolInfo {
+ return this.pool.info;
+ }
+
get size(): number {
get size(): number {
- return this.pool.
workers.length
;
+ return this.pool.
info.workerNodes
;
}
}
- get maxElementsPerWorker(): number |
null
{
- return
null
;
+ get maxElementsPerWorker(): number |
undefined
{
+ return
undefined
;
}
}
- /**
- *
- * @returns
- * @public
- */
+ get emitter(): EventEmitterAsyncResource | undefined {
+ return this.pool?.emitter;
+ }
+
+
/** @inheritDoc
*/
public async start(): Promise<void> {
// This is intentional
}
public async start(): Promise<void> {
// This is intentional
}
- /**
- *
- * @returns
- * @public
- */
+ /** @inheritDoc */
public async stop(): Promise<void> {
return this.pool.destroy();
}
public async stop(): Promise<void> {
return this.pool.destroy();
}
- /**
- *
- * @param elementData
- * @returns
- * @public
- */
+ /** @inheritDoc */
public async addElement(elementData: WorkerData): Promise<void> {
await this.pool.execute(elementData);
// Start element sequentially to optimize memory at startup
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 Utils.sleep(this.workerOptions.elementStartDelay));
+ this.workerOptions.elementStartDelay > 0 && (await sleep(this.workerOptions.elementStartDelay));
}
}
}
}