Increased test timeouts, we need to look into that as soon as we can
[poolifier.git] / src / pools / thread / dynamic.ts
index 92a5fdf2b20da75e14f08d1c1e98e8637314a3f8..7a0d4ffd8c0513bac3a4ffaf983182f109d23b3d 100644 (file)
@@ -2,6 +2,7 @@ import type { JSONValue } from '../../utility-types'
 import type { PoolOptions } from '../abstract-pool'
 import type { ThreadWorkerWithMessageChannel } from './fixed'
 import { FixedThreadPool } from './fixed'
+import { killBehaviorEnumeration } from '../../worker/worker-options'
 
 /**
  * A thread pool with a dynamic number of threads, but a guaranteed minimum number of threads.
@@ -62,10 +63,10 @@ export class DynamicThreadPool<
     const worker = this.createAndSetupWorker()
     this.registerWorkerMessageListener<Data>(worker, message => {
       const tasksInProgress = this.tasks.get(worker)
-      if (message.kill && !tasksInProgress) {
-        // Kill received from the worker, means that no new tasks are submitted to that worker for a while( > maxInactiveTime)
-        // To handle the case of a long-running task we will check if the there is any active task
-        console.log('Here we are')
+      const isKillBehaviorOptionHard =
+        message.kill === killBehaviorEnumeration.HARD
+      if (isKillBehaviorOptionHard || tasksInProgress === 0) {
+        // Kill received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime)
         this.sendToWorker(worker, { kill: 1 })
         void this.destroyWorker(worker)
       }