} from '../utils'
import { KillBehaviors, isKillBehavior } from '../worker/worker-options'
import {
+ PoolEmitter,
PoolEvents,
type IPool,
type PoolOptions,
type TasksQueueOptions,
PoolType
} from './pool'
-import { PoolEmitter } from './pool'
import type { IWorker, Task, TasksUsage, WorkerNode } from './worker'
import {
WorkerChoiceStrategies,
protected abstract get busy (): boolean
protected internalBusy (): boolean {
- return this.findFreeWorkerNodeKey() === -1
- }
-
- /** @inheritDoc */
- public findFreeWorkerNodeKey (): number {
- return this.workerNodes.findIndex(workerNode => {
- return workerNode.tasksUsage?.running === 0
- })
- }
-
- /** @inheritDoc */
- public findLastFreeWorkerNodeKey (): number {
- // It requires node >= 18.0.0
- // return this.workerNodes.findLastIndex(workerNode => {
- // return workerNode.tasksUsage?.running === 0
- // })
- for (let i = this.workerNodes.length - 1; i >= 0; i--) {
- if (this.workerNodes[i].tasksUsage?.running === 0) {
- return i
- }
- }
- return -1
+ return (
+ this.workerNodes.findIndex(workerNode => {
+ return workerNode.tasksUsage?.running === 0
+ }) === -1
+ )
}
/** @inheritDoc */
) {
// 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)
+ void (this.destroyWorker(workerCreated) as Promise<void>)
}
})
workerNodeKey = this.getWorkerNodeKey(workerCreated)