+import type { IPool } from '../pool.js'
import {
DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
buildWorkerChoiceStrategyOptions
-} from '../../utils.js'
-import type { IPool } from '../pool.js'
+} from '../utils.js'
import type { IWorker } from '../worker.js'
import type {
IWorkerChoiceStrategy,
/**
* The previous worker node key.
*/
- protected previousWorkerNodeKey: number = 0
+ protected previousWorkerNodeKey = 0
/** @inheritDoc */
public readonly strategyPolicy: StrategyPolicy = {
protected readonly pool: IPool<Worker, Data, Response>,
protected opts?: WorkerChoiceStrategyOptions
) {
- this.setOptions(this.opts)
this.choose = this.choose.bind(this)
+ this.setOptions(this.opts)
}
protected setTaskStatisticsRequirements (
}
/**
- * Check the next worker node readiness.
+ * Check the next worker node key.
*/
- protected checkNextWorkerNodeReadiness (): void {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- if (!this.isWorkerNodeReady(this.nextWorkerNodeKey!)) {
+ protected checkNextWorkerNodeKey (): void {
+ if (
+ this.nextWorkerNodeKey != null &&
+ (this.nextWorkerNodeKey < 0 ||
+ !this.isWorkerNodeReady(this.nextWorkerNodeKey))
+ ) {
delete this.nextWorkerNodeKey
}
}
* @param workerNodeKey - The worker node key.
*/
protected setPreviousWorkerNodeKey (workerNodeKey: number | undefined): void {
- this.previousWorkerNodeKey = workerNodeKey ?? this.previousWorkerNodeKey
+ this.previousWorkerNodeKey =
+ workerNodeKey != null && workerNodeKey >= 0
+ ? workerNodeKey
+ : this.previousWorkerNodeKey
}
}