refactor: add sanity checks to worker set arguments
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 28 Jul 2023 10:55:15 +0000 (12:55 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 28 Jul 2023 10:55:15 +0000 (12:55 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/worker/WorkerSet.ts

index fd81840a7a35139e238ff203facef400576e6572..0f8204118afb3efad9158a78e23bea51e1247534 100644 (file)
@@ -35,6 +35,18 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
    */
   constructor(workerScript: string, workerOptions: WorkerOptions) {
     super(workerScript, workerOptions);
+    if (
+      this.workerOptions.elementsPerWorker === null ||
+      this.workerOptions.elementsPerWorker === undefined
+    ) {
+      throw new TypeError('Elements per worker is not defined');
+    }
+    if (Number.isSafeInteger(this.workerOptions.elementsPerWorker)) {
+      throw new TypeError('Elements per worker must be an integer');
+    }
+    if (this.workerOptions.elementsPerWorker <= 0) {
+      throw new RangeError('Elements per worker must be greater than zero');
+    }
     this.workerOptions.poolOptions = {
       ...DEFAULT_POOL_OPTIONS,
       ...this.workerOptions.poolOptions,