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
Update deps
[e-mobility-charging-stations-simulator.git]
/
src
/
worker
/
WorkerStaticPool.ts
diff --git
a/src/worker/WorkerStaticPool.ts
b/src/worker/WorkerStaticPool.ts
index 20d53b0e02d305e9f4623175cdca0301a737a81b..ab8e309f208f4655ff0ba6acb96929fea12c8d3d 100644
(file)
--- a/
src/worker/WorkerStaticPool.ts
+++ b/
src/worker/WorkerStaticPool.ts
@@
-1,12
+1,12
@@
-import { FixedThreadPool,
FixedThread
PoolOptions } from 'poolifier';
+import { FixedThreadPool, PoolOptions } from 'poolifier';
import Constants from '../utils/Constants';
import Utils from '../utils/Utils';
import Constants from '../utils/Constants';
import Utils from '../utils/Utils';
+import { Worker } from 'worker_threads';
+import WorkerAbstract from './WorkerAbstract';
import { WorkerData } from '../types/Worker';
import { WorkerData } from '../types/Worker';
-import Wrk from './Wrk';
-import { threadId } from 'worker_threads';
-export default class WorkerStaticPool
extends Wrk
{
+export default class WorkerStaticPool
<T> extends WorkerAbstract
{
private pool: StaticPool;
/**
private pool: StaticPool;
/**
@@
-14,9
+14,9
@@
export default class WorkerStaticPool extends Wrk {
*
* @param {string} workerScript
*/
*
* @param {string} workerScript
*/
- constructor(workerScript: string, numThreads: number) {
+ constructor(workerScript: string, num
berOf
Threads: number) {
super(workerScript);
super(workerScript);
- this.pool = StaticPool.getInstance(numThreads, this.workerScript);
+ this.pool = StaticPool.getInstance(num
berOf
Threads, this.workerScript);
}
get size(): number {
}
get size(): number {
@@
-24,7
+24,7
@@
export default class WorkerStaticPool extends Wrk {
}
get maxElementsPerWorker(): number {
}
get maxElementsPerWorker(): number {
- return
1
;
+ return
null
;
}
/**
}
/**
@@
-40,7
+40,16
@@
export default class WorkerStaticPool extends Wrk {
* @return {Promise<void>}
* @public
*/
* @return {Promise<void>}
* @public
*/
- public async addElement(elementData: WorkerData): Promise<void> {
+ public async stop(): Promise<void> {
+ return this.pool.destroy();
+ }
+
+ /**
+ *
+ * @return {Promise<void>}
+ * @public
+ */
+ public async addElement(elementData: T): Promise<void> {
await this.pool.execute(elementData);
// Start worker sequentially to optimize memory at startup
await Utils.sleep(Constants.START_WORKER_DELAY);
await this.pool.execute(elementData);
// Start worker sequentially to optimize memory at startup
await Utils.sleep(Constants.START_WORKER_DELAY);
@@
-50,17
+59,17
@@
export default class WorkerStaticPool extends Wrk {
class StaticPool extends FixedThreadPool<WorkerData> {
private static instance: StaticPool;
class StaticPool extends FixedThreadPool<WorkerData> {
private static instance: StaticPool;
- private constructor(num
Threads: number, workerScript: string, opts?: FixedThreadPoolOptions
) {
- super(numThreads, workerScript, opts);
+ private constructor(num
berOfThreads: number, workerScript: string, opts?: PoolOptions<Worker>
) {
+ super(num
berOf
Threads, workerScript, opts);
}
}
- public static getInstance(numThreads: number, workerScript: string): StaticPool {
+ public static getInstance(num
berOf
Threads: number, workerScript: string): StaticPool {
if (!StaticPool.instance) {
if (!StaticPool.instance) {
- StaticPool.instance = new StaticPool(numThreads, workerScript,
+ StaticPool.instance = new StaticPool(num
berOf
Threads, workerScript,
{
exitHandler: (code) => {
if (code !== 0) {
{
exitHandler: (code) => {
if (code !== 0) {
- console.error(`Worker
${threadId}
stopped with exit code ${code}`);
+ console.error(`Worker stopped with exit code ${code}`);
}
}
}
}
}
}