X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fabstract-worker-choice-strategy.ts;h=332b3fc103bdffcd2e0339d1153651441d2c29da;hb=2285a040e7d48457c735547e296939b0341d29fd;hp=314c13c0cd02063a569a8ee5997a1d748b13cdbd;hpb=38e795c12f0e9daeff7b025147f36f85f486366e;p=poolifier.git diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index 314c13c0..332b3fc1 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -7,7 +7,7 @@ import type { } from './selection-strategies-types' /** - * Abstract worker choice strategy class. + * Worker choice strategy abstract base class. * * @typeParam Worker - Type of worker which manages the strategy. * @typeParam Data - Type of data sent to the worker. This can only be serializable data. @@ -15,28 +15,35 @@ import type { */ export abstract class AbstractWorkerChoiceStrategy< Worker extends IPoolWorker, - Data, - Response -> implements IWorkerChoiceStrategy { + Data = unknown, + Response = unknown +> implements IWorkerChoiceStrategy { /** {@inheritDoc} */ - public readonly isDynamicPool: boolean = this.pool.type === PoolType.DYNAMIC + public readonly isDynamicPool: boolean /** {@inheritDoc} */ public requiredStatistics: RequiredStatistics = { - runTime: false + runTime: false, + avgRunTime: false } /** - * Constructs a worker choice strategy attached to the pool. + * Constructs a worker choice strategy bound to the pool. * * @param pool - The pool instance. */ public constructor ( - protected readonly pool: IPoolInternal - ) {} + public readonly pool: IPoolInternal + ) { + this.isDynamicPool = this.pool.type === PoolType.DYNAMIC + this.choose.bind(this) + } /** {@inheritDoc} */ public abstract reset (): boolean /** {@inheritDoc} */ - public abstract choose (): Worker + public abstract choose (): number + + /** {@inheritDoc} */ + public abstract remove (workerKey: number): boolean }