+ protected chooseWorkerNode (): [number, WorkerNode<Worker, Data>] {
+ let workerNodeKey: number
+ if (
+ this.type === PoolType.DYNAMIC &&
+ !this.full &&
+ this.findFreeWorkerNodeKey() === -1
+ ) {
+ const workerCreated = this.createAndSetupWorker()
+ this.registerWorkerMessageListener(workerCreated, message => {
+ if (
+ isKillBehavior(KillBehaviors.HARD, message.kill) ||
+ (message.kill != null &&
+ this.getWorkerTasksUsage(workerCreated)?.running === 0)
+ ) {
+ // Kill message received from the worker: no new tasks are submitted to that worker for a while ( > maxInactiveTime)
+ this.flushTasksQueueByWorker(workerCreated)
+ void this.destroyWorker(workerCreated)
+ }
+ })
+ workerNodeKey = this.getWorkerNodeKey(workerCreated)
+ } else {
+ workerNodeKey = this.workerChoiceStrategyContext.execute()
+ }
+ return [workerNodeKey, this.workerNodes[workerNodeKey]]