Merge pull request #2174 from poolifier/task-functions-properties
[poolifier.git] / src / pools / utils.ts
index 6a6c1fa9d3aa9d14946d760e09301ad878ce901a..3fa17312d1fe24f54fb121eeda4d9dee6124e0c9 100644 (file)
@@ -87,6 +87,19 @@ export const checkDynamicPoolSize = (
   }
 }
 
+export const checkValidPriority = (priority: number | undefined): void => {
+  if (priority != null && !Number.isSafeInteger(priority)) {
+    throw new TypeError(`Invalid property 'priority': '${priority}'`)
+  }
+  if (
+    priority != null &&
+    Number.isSafeInteger(priority) &&
+    (priority < -20 || priority > 19)
+  ) {
+    throw new RangeError("Property 'priority' must be between -20 and 19")
+  }
+}
+
 export const checkValidWorkerChoiceStrategy = (
   workerChoiceStrategy: WorkerChoiceStrategy | undefined
 ): void => {