fix: null expection in
[poolifier.git] / src / pools / abstract-pool.ts
index 10c99171dcf06349063fd59772fe4a889c11d346..d65ac2ffe7a92775e428e1a28ba8867a681ec136 100644 (file)
@@ -1671,23 +1671,23 @@ export abstract class AbstractPool<
     if (workerNode?.usage != null) {
       ++workerNode.usage.tasks.sequentiallyStolen
     }
-    const taskFunctionWorkerUsage =
-      workerNode.getTaskFunctionWorkerUsage(taskName)
     if (
       this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
-      taskFunctionWorkerUsage != null &&
-      (taskFunctionWorkerUsage.tasks.sequentiallyStolen === 0 ||
+      workerNode.getTaskFunctionWorkerUsage(taskName) != null
+    ) {
+      const taskFunctionWorkerUsage =
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        workerNode.getTaskFunctionWorkerUsage(taskName)!
+      if (
+        taskFunctionWorkerUsage.tasks.sequentiallyStolen === 0 ||
         (previousTaskName != null &&
           previousTaskName === taskName &&
-          taskFunctionWorkerUsage.tasks.sequentiallyStolen > 0))
-    ) {
-      ++taskFunctionWorkerUsage.tasks.sequentiallyStolen
-    } else if (
-      this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
-      taskFunctionWorkerUsage != null &&
-      taskFunctionWorkerUsage.tasks.sequentiallyStolen > 0
-    ) {
-      taskFunctionWorkerUsage.tasks.sequentiallyStolen = 0
+          taskFunctionWorkerUsage.tasks.sequentiallyStolen > 0)
+      ) {
+        ++taskFunctionWorkerUsage.tasks.sequentiallyStolen
+      } else if (taskFunctionWorkerUsage.tasks.sequentiallyStolen > 0) {
+        taskFunctionWorkerUsage.tasks.sequentiallyStolen = 0
+      }
     }
   }