perf: improve node eligibility branching on worker choice strategies
[poolifier.git] / src / utils.ts
index 21b2032b47086484e2b39475b06310950d95c08b..54d0d8d6d3c20b822f7138229a3e31d583f7ce3e 100644 (file)
@@ -67,6 +67,40 @@ export const availableParallelism = (): number => {
   return availableParallelism
 }
 
+/**
+ * Returns the worker type of the given worker.
+ *
+ * @param worker - The worker to get the type of.
+ * @returns The worker type of the given worker.
+ * @internal
+ */
+export const getWorkerType = <Worker extends IWorker>(
+  worker: Worker
+): WorkerType | undefined => {
+  if (worker instanceof ThreadWorker) {
+    return WorkerTypes.thread
+  } else if (worker instanceof ClusterWorker) {
+    return WorkerTypes.cluster
+  }
+}
+
+/**
+ * Returns the worker id of the given worker.
+ *
+ * @param worker - The worker to get the id of.
+ * @returns The worker id of the given worker.
+ * @internal
+ */
+export const getWorkerId = <Worker extends IWorker>(
+  worker: Worker
+): number | undefined => {
+  if (worker instanceof ThreadWorker) {
+    return worker.threadId
+  } else if (worker instanceof ClusterWorker) {
+    return worker.id
+  }
+}
+
 /**
  * Sleeps for the given amount of milliseconds.
  *
@@ -116,41 +150,6 @@ export const average = (dataSet: number[]): number => {
   )
 }
 
-/**
- * Returns the worker type of the given worker.
- *
- * @param worker - The worker to get the type of.
- * @returns The worker type of the given worker.
- * @internal
- */
-export const getWorkerType = <Worker extends IWorker>(
-  worker: Worker
-): WorkerType | undefined => {
-  if (worker instanceof ThreadWorker) {
-    return WorkerTypes.thread
-  }
-  if (worker instanceof ClusterWorker) {
-    return WorkerTypes.cluster
-  }
-}
-
-/**
- * Returns the worker id of the given worker.
- *
- * @param worker - The worker to get the id of.
- * @returns The worker id of the given worker.
- * @internal
- */
-export const getWorkerId = <Worker extends IWorker>(
-  worker: Worker
-): number | undefined => {
-  if (worker instanceof ThreadWorker) {
-    return worker.threadId
-  } else if (worker instanceof ClusterWorker) {
-    return worker.id
-  }
-}
-
 /**
  * Computes the median of the given data set.
  *