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 = unknown,
+ Response = unknown
+ >
+ extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
+ implements IWorkerChoiceStrategy<Worker, Data, Response> {
/** {@inheritDoc} */
public readonly requiredStatistics: RequiredStatistics = {
- runTime: true
+ runTime: true,
+ avgRunTime: false
}
/** {@inheritDoc} */
/** {@inheritDoc} */
public choose (): number {
const freeWorkerKey = this.pool.findFreeWorkerKey()
- if (!this.isDynamicPool && freeWorkerKey !== false) {
+ if (freeWorkerKey !== -1) {
return freeWorkerKey
}
let minRunTime = Infinity