protected internalGetBusyStatus (): 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 no free worker is found, `false` is returned.
*
- * @returns A worker key if there is one, otherwise `false`.
+ * @returns A worker key if there is one, `-1` otherwise.
*/
- findFreeWorkerKey: () => number | false
+ findFreeWorkerKey: () => number
}
* @typeParam Response - Type of response of execution. This can only be serializable data.
*/
export class DynamicPoolWorkerChoiceStrategy<
- Worker extends IPoolWorker,
- Data,
- Response
-> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> {
+ Worker extends IPoolWorker,
+ Data,
+ Response
+ >
+ extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
+ implements IWorkerChoiceStrategy {
private readonly workerChoiceStrategy: IWorkerChoiceStrategy
/**
/** {@inheritDoc} */
public choose (): number {
const freeWorkerKey = this.pool.findFreeWorkerKey()
- if (freeWorkerKey !== false) {
+ if (freeWorkerKey !== -1) {
return freeWorkerKey
}
import type { IPoolWorker } from '../pool-worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
-import type { RequiredStatistics } from './selection-strategies-types'
+import type {
+ IWorkerChoiceStrategy,
+ RequiredStatistics
+} from './selection-strategies-types'
/**
* Worker virtual task timestamp.
* @typeParam Response - Type of response of execution. This can only be serializable data.
*/
export class FairShareWorkerChoiceStrategy<
- Worker extends IPoolWorker,
- Data,
- Response
-> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> {
+ Worker extends IPoolWorker,
+ Data,
+ Response
+ >
+ extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
+ implements IWorkerChoiceStrategy {
/** {@inheritDoc} */
public readonly requiredStatistics: RequiredStatistics = {
runTime: true
import type { IPoolWorker } from '../pool-worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
-import type { RequiredStatistics } from './selection-strategies-types'
+import type {
+ IWorkerChoiceStrategy,
+ RequiredStatistics
+} from './selection-strategies-types'
/**
* Selects the less busy worker.
* @typeParam Response - Type of response of execution. This can only be serializable data.
*/
export class LessBusyWorkerChoiceStrategy<
- Worker extends IPoolWorker,
- Data,
- Response
-> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> {
+ Worker extends IPoolWorker,
+ Data,
+ Response
+ >
+ extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
+ implements IWorkerChoiceStrategy {
/** {@inheritDoc} */
public readonly requiredStatistics: RequiredStatistics = {
runTime: true
/** {@inheritDoc} */
public choose (): number {
const freeWorkerKey = this.pool.findFreeWorkerKey()
- if (!this.isDynamicPool && freeWorkerKey !== false) {
+ if (!this.isDynamicPool && freeWorkerKey !== -1) {
return freeWorkerKey
}
let minRunTime = Infinity
import type { IPoolWorker } from '../pool-worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
+import type { IWorkerChoiceStrategy } from './selection-strategies-types'
/**
* Selects the less used worker.
* @typeParam Response - Type of response of execution. This can only be serializable data.
*/
export class LessUsedWorkerChoiceStrategy<
- Worker extends IPoolWorker,
- Data,
- Response
-> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> {
+ Worker extends IPoolWorker,
+ Data,
+ Response
+ >
+ extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
+ implements IWorkerChoiceStrategy {
/** {@inheritDoc} */
public reset (): boolean {
return true
/** {@inheritDoc} */
public choose (): number {
const freeWorkerKey = this.pool.findFreeWorkerKey()
- if (!this.isDynamicPool && freeWorkerKey !== false) {
+ if (!this.isDynamicPool && freeWorkerKey !== -1) {
return freeWorkerKey
}
let minNumberOfTasks = Infinity
import type { IPoolWorker } from '../pool-worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
+import type { IWorkerChoiceStrategy } from './selection-strategies-types'
/**
* Selects the next worker in a round robin fashion.
* @typeParam Response - Type of response of execution. This can only be serializable data.
*/
export class RoundRobinWorkerChoiceStrategy<
- Worker extends IPoolWorker,
- Data,
- Response
-> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> {
+ Worker extends IPoolWorker,
+ Data,
+ Response
+ >
+ extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
+ implements IWorkerChoiceStrategy {
/**
* Id of the next worker.
*/
import type { IPoolInternal } from '../pool-internal'
import type { IPoolWorker } from '../pool-worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
-import type { RequiredStatistics } from './selection-strategies-types'
+import type {
+ IWorkerChoiceStrategy,
+ RequiredStatistics
+} from './selection-strategies-types'
/**
* Virtual task runtime.
* @typeParam Response - Type of response of execution. This can only be serializable data.
*/
export class WeightedRoundRobinWorkerChoiceStrategy<
- Worker extends IPoolWorker,
- Data,
- Response
-> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> {
+ Worker extends IPoolWorker,
+ Data,
+ Response
+ >
+ extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
+ implements IWorkerChoiceStrategy {
/** {@inheritDoc} */
public readonly requiredStatistics: RequiredStatistics = {
runTime: true