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
docs: enhance code documentation
[e-mobility-charging-stations-simulator.git]
/
src
/
worker
/
WorkerAbstract.ts
diff --git
a/src/worker/WorkerAbstract.ts
b/src/worker/WorkerAbstract.ts
index bfb7933639eb1e3445e6bd71cafeef12807f2b3e..3dd9a782a8661507f61fa21787ed9f80c9465852 100644
(file)
--- a/
src/worker/WorkerAbstract.ts
+++ b/
src/worker/WorkerAbstract.ts
@@
-1,18
+1,19
@@
-import
{ WorkerData, WorkerOptions } from '../types/Worker
';
+import
fs from 'node:fs
';
-import WorkerConstants from './WorkerConstants';
+import { WorkerConstants } from './WorkerConstants';
+import type { WorkerData, WorkerOptions } from './WorkerTypes';
-export
default
abstract class WorkerAbstract<T extends WorkerData> {
+export abstract class WorkerAbstract<T extends WorkerData> {
protected readonly workerScript: string;
protected readonly workerOptions: WorkerOptions;
public abstract readonly size: number;
protected readonly workerScript: string;
protected readonly workerOptions: WorkerOptions;
public abstract readonly size: number;
- public abstract readonly maxElementsPerWorker: number |
null
;
+ public abstract readonly maxElementsPerWorker: number |
undefined
;
/**
* `WorkerAbstract` constructor.
*
/**
* `WorkerAbstract` constructor.
*
- * @param workerScript
- * @param workerOptions
+ * @param workerScript
-
+ * @param workerOptions
-
*/
constructor(
workerScript: string,
*/
constructor(
workerScript: string,
@@
-23,11
+24,15
@@
export default abstract class WorkerAbstract<T extends WorkerData> {
poolMaxSize: WorkerConstants.DEFAULT_POOL_MAX_SIZE,
elementsPerWorker: WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER,
poolOptions: {},
poolMaxSize: WorkerConstants.DEFAULT_POOL_MAX_SIZE,
elementsPerWorker: WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER,
poolOptions: {},
- messageHandler: () => {
- /* This is intentional */
- },
+ messageHandler: WorkerConstants.EMPTY_FUNCTION,
}
) {
}
) {
+ if (!workerScript) {
+ throw new Error('Worker script is not defined');
+ }
+ if (!fs.existsSync(workerScript)) {
+ throw new Error('Worker script file does not exist');
+ }
this.workerScript = workerScript;
this.workerOptions = workerOptions;
}
this.workerScript = workerScript;
this.workerOptions = workerOptions;
}