+ private checkFilePath (filePath: string): void {
+ if (!filePath) {
+ throw new Error('Please specify a file with a worker implementation')
+ }
+ }
+
+ private checkNumberOfWorkers (numberOfWorkers: number): void {
+ if (numberOfWorkers == null) {
+ throw new Error(
+ 'Cannot instantiate a pool without specifying the number of workers'
+ )
+ } else if (!Number.isSafeInteger(numberOfWorkers)) {
+ throw new Error(
+ 'Cannot instantiate a pool with a non integer number of workers'
+ )
+ } else if (numberOfWorkers < 0) {
+ throw new Error(
+ 'Cannot instantiate a pool with a negative number of workers'
+ )
+ } else if (this.type === PoolType.FIXED && numberOfWorkers === 0) {
+ throw new Error('Cannot instantiate a fixed pool with no worker')
+ }
+ }
+
+ private checkPoolOptions (opts: PoolOptions<Worker>): void {
+ this.opts.workerChoiceStrategy =
+ opts.workerChoiceStrategy ?? WorkerChoiceStrategies.ROUND_ROBIN
+ this.opts.enableEvents = opts.enableEvents ?? true
+ }
+
+ /** @inheritdoc */
+ public abstract get type (): PoolType
+
+ /** @inheritdoc */
+ public get numberOfRunningTasks (): number {
+ return this.promiseMap.size
+ }
+
+ /** @inheritdoc */
+ public setWorkerChoiceStrategy (
+ workerChoiceStrategy: WorkerChoiceStrategy
+ ): void {
+ this.opts.workerChoiceStrategy = workerChoiceStrategy
+ this.workerChoiceStrategyContext.setWorkerChoiceStrategy(
+ workerChoiceStrategy
+ )
+ }
+
+ /** @inheritdoc */
+ public abstract get busy (): boolean
+
+ protected internalGetBusyStatus (): boolean {
+ return (
+ this.numberOfRunningTasks >= this.numberOfWorkers &&
+ this.findFreeTasksMapEntry() === false
+ )
+ }
+
+ /** @inheritdoc */
+ public findFreeTasksMapEntry (): [Worker, number] | false {
+ for (const [worker, numberOfTasks] of this.tasks) {
+ if (numberOfTasks === 0) {
+ // A worker is free, return the matching tasks map entry
+ return [worker, numberOfTasks]
+ }
+ }
+ return false
+ }
+
+ /** @inheritdoc */