- /**
- * Perform the task specified in the constructor with the data parameter.
- *
- * @param data The input for the specified task.
- * @returns Promise that will be resolved when the task is successfully completed.
- */
+ 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 */