perf: bind to this some methods in the tasks execution code path
[poolifier.git] / src / pools / selection-strategies / abstract-worker-choice-strategy.ts
CommitLineData
bdaf31cd
JB
1import type { IPoolInternal } from '../pool-internal'
2import { PoolType } from '../pool-internal'
ea7a90d3 3import type { IPoolWorker } from '../pool-worker'
10fcfaf4
JB
4import type {
5 IWorkerChoiceStrategy,
6 RequiredStatistics
7} from './selection-strategies-types'
bdaf31cd
JB
8
9/**
10 * Abstract worker choice strategy class.
11 *
38e795c1
JB
12 * @typeParam Worker - Type of worker which manages the strategy.
13 * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
14 * @typeParam Response - Type of response of execution. This can only be serializable data.
bdaf31cd
JB
15 */
16export abstract class AbstractWorkerChoiceStrategy<
ea7a90d3 17 Worker extends IPoolWorker,
bdaf31cd
JB
18 Data,
19 Response
c923ce56 20> implements IWorkerChoiceStrategy {
38e795c1 21 /** {@inheritDoc} */
b8f3418c 22 public readonly isDynamicPool: boolean
38e795c1 23 /** {@inheritDoc} */
10fcfaf4 24 public requiredStatistics: RequiredStatistics = {
c6bd2650
JB
25 runTime: false,
26 avgRunTime: false
10fcfaf4 27 }
bdaf31cd
JB
28
29 /**
30 * Constructs a worker choice strategy attached to the pool.
31 *
38e795c1 32 * @param pool - The pool instance.
bdaf31cd
JB
33 */
34 public constructor (
35 protected readonly pool: IPoolInternal<Worker, Data, Response>
b8f3418c
JB
36 ) {
37 this.isDynamicPool = this.pool.type === PoolType.DYNAMIC
1086026a 38 this.choose.bind(this)
b8f3418c 39 }
bdaf31cd 40
38e795c1 41 /** {@inheritDoc} */
a6f7f1b4 42 public abstract reset (): boolean
ea7a90d3 43
38e795c1 44 /** {@inheritDoc} */
c923ce56 45 public abstract choose (): number
97a2abc3
JB
46
47 /** {@inheritDoc} */
48 public abstract remove (workerKey: number): boolean
bdaf31cd 49}