this.checkNumberOfWorkers(this.numberOfWorkers)
this.checkFilePath(this.filePath)
this.checkPoolOptions(this.opts)
+
+ this.chooseWorker.bind(this)
+ this.internalExecute.bind(this)
+ this.checkAndEmitBusy.bind(this)
+ this.sendToWorker.bind(this)
+
this.setupHook()
for (let i = 1; i <= this.numberOfWorkers; i++) {
/** {@inheritDoc} */
public abstract get type (): PoolType
- /** {@inheritDoc} */
- public get numberOfRunningTasks (): number {
+ /**
+ * Number of tasks concurrently running.
+ */
+ private get numberOfRunningTasks (): number {
return this.promiseResponseMap.size
}
* Gets the given worker key.
*
* @param worker - The worker.
- * @returns The worker key.
+ * @returns The worker key if the worker is found in the pool, `-1` otherwise.
*/
private getWorkerKey (worker: Worker): number {
return this.workers.findIndex(workerItem => workerItem.worker === worker)
)
}
+ /** {@inheritDoc} */
+ public abstract get full (): boolean
+
/** {@inheritDoc} */
public abstract get busy (): boolean
- protected internalGetBusyStatus (): boolean {
+ protected internalBusy (): boolean {
return (
this.numberOfRunningTasks >= this.numberOfWorkers &&
- this.findFreeWorkerKey() === false
+ this.findFreeWorkerKey() === -1
)
}
/** {@inheritDoc} */
- public findFreeWorkerKey (): number | false {
- const freeWorkerKey = this.workers.findIndex(workerItem => {
+ public findFreeWorkerKey (): number {
+ return this.workers.findIndex(workerItem => {
return workerItem.tasksUsage.running === 0
})
- return freeWorkerKey !== -1 ? freeWorkerKey : false
}
/** {@inheritDoc} */
if (message.error != null) {
++workerTasksUsage.error
}
- if (
- this.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
- ) {
+ if (this.workerChoiceStrategyContext.getRequiredStatistics().runTime) {
workerTasksUsage.runTime += message.taskRunTime ?? 0
- if (workerTasksUsage.run !== 0) {
+ if (
+ this.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime &&
+ workerTasksUsage.run !== 0
+ ) {
workerTasksUsage.avgRunTime =
workerTasksUsage.runTime / workerTasksUsage.run
}
* @param worker - The worker that will be removed.
*/
protected removeWorker (worker: Worker): void {
- this.workers.splice(this.getWorkerKey(worker), 1)
+ const workerKey = this.getWorkerKey(worker)
+ this.workers.splice(workerKey, 1)
+ this.workerChoiceStrategyContext.remove(workerKey)
}
/**