repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: apply stricter strategy design pattern requirements on worker
[poolifier.git]
/
src
/
pools
/
selection-strategies
/
worker-choice-strategy-context.ts
diff --git
a/src/pools/selection-strategies/worker-choice-strategy-context.ts
b/src/pools/selection-strategies/worker-choice-strategy-context.ts
index f6e0feab2e8cb425fec1da9f420deba8b75135e1..41b515b816d00dc991c27d8143efe80ec7c6116a 100644
(file)
--- a/
src/pools/selection-strategies/worker-choice-strategy-context.ts
+++ b/
src/pools/selection-strategies/worker-choice-strategy-context.ts
@@
-1,5
+1,4
@@
import type { IPoolInternal } from '../pool-internal'
import type { IPoolInternal } from '../pool-internal'
-import { PoolType } from '../pool-internal'
import type { IPoolWorker } from '../pool-worker'
import type {
IWorkerChoiceStrategy,
import type { IPoolWorker } from '../pool-worker'
import type {
IWorkerChoiceStrategy,
@@
-21,7
+20,7
@@
export class WorkerChoiceStrategyContext<
Data,
Response
> {
Data,
Response
> {
- private workerChoiceStrategy
!: IWorkerChoiceStrategy
+ private workerChoiceStrategy
: IWorkerChoiceStrategy<Worker, Data, Response>
/**
* Worker choice strategy context constructor.
/**
* Worker choice strategy context constructor.
@@
-31,12
+30,15
@@
export class WorkerChoiceStrategyContext<
* @param workerChoiceStrategy - The worker choice strategy.
*/
public constructor (
* @param workerChoiceStrategy - The worker choice strategy.
*/
public constructor (
- p
rivate readonly p
ool: IPoolInternal<Worker, Data, Response>,
+ pool: IPoolInternal<Worker, Data, Response>,
private readonly createWorkerCallback: () => number,
workerChoiceStrategy: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
) {
this.execute.bind(this)
private readonly createWorkerCallback: () => number,
workerChoiceStrategy: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
) {
this.execute.bind(this)
- this.setWorkerChoiceStrategy(workerChoiceStrategy)
+ this.workerChoiceStrategy = getWorkerChoiceStrategy<Worker, Data, Response>(
+ pool,
+ workerChoiceStrategy
+ )
}
/**
}
/**
@@
-54,11
+56,12
@@
export class WorkerChoiceStrategyContext<
* @param workerChoiceStrategy - The worker choice strategy to set.
*/
public setWorkerChoiceStrategy (
* @param workerChoiceStrategy - The worker choice strategy to set.
*/
public setWorkerChoiceStrategy (
+ pool: IPoolInternal<Worker, Data, Response>,
workerChoiceStrategy: WorkerChoiceStrategy
): void {
this.workerChoiceStrategy?.reset()
workerChoiceStrategy: WorkerChoiceStrategy
): void {
this.workerChoiceStrategy?.reset()
- this.workerChoiceStrategy = getWorkerChoiceStrategy(
-
this.
pool,
+ this.workerChoiceStrategy = getWorkerChoiceStrategy
<Worker, Data, Response>
(
+ pool,
workerChoiceStrategy
)
}
workerChoiceStrategy
)
}
@@
-70,9
+73,9
@@
export class WorkerChoiceStrategyContext<
*/
public execute (): number {
if (
*/
public execute (): number {
if (
- this.
pool.type === PoolType.DYNAMIC
&&
- !this.pool.full &&
- this.pool.findFreeWorkerKey() === -1
+ this.
workerChoiceStrategy.isDynamicPool
&&
+ !this.
workerChoiceStrategy.
pool.full &&
+ this.
workerChoiceStrategy.
pool.findFreeWorkerKey() === -1
) {
return this.createWorkerCallback()
}
) {
return this.createWorkerCallback()
}