repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
docs: add changelog entry
[poolifier.git]
/
src
/
pools
/
selection-strategies
/
round-robin-worker-choice-strategy.ts
diff --git
a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
index 835860930b0d76f54c37d547b73274d9bf7fb175..b023234a202cacc50b8f2505859e4e444bcf8f0f 100644
(file)
--- a/
src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
+++ b/
src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
@@
-38,7
+38,7
@@
export class RoundRobinWorkerChoiceStrategy<
/** @inheritDoc */
public reset (): boolean {
/** @inheritDoc */
public reset (): boolean {
- this.nextWorkerNode
Id
= 0
+ this.nextWorkerNode
Key
= 0
return true
}
return true
}
@@
-49,23
+49,30
@@
export class RoundRobinWorkerChoiceStrategy<
/** @inheritDoc */
public choose (): number {
/** @inheritDoc */
public choose (): number {
- const chosenWorkerNodeKey = this.nextWorkerNodeId
- this.nextWorkerNodeId =
- this.nextWorkerNodeId === this.pool.workerNodes.length - 1
- ? 0
- : this.nextWorkerNodeId + 1
+ const chosenWorkerNodeKey = this.nextWorkerNodeKey
+ do {
+ this.roundRobinNextWorkerNodeKey()
+ } while (!this.isWorkerNodeReady(this.nextWorkerNodeKey))
return chosenWorkerNodeKey
}
/** @inheritDoc */
public remove (workerNodeKey: number): boolean {
return chosenWorkerNodeKey
}
/** @inheritDoc */
public remove (workerNodeKey: number): boolean {
- if (this.nextWorkerNode
Id
=== workerNodeKey) {
+ if (this.nextWorkerNode
Key
=== workerNodeKey) {
if (this.pool.workerNodes.length === 0) {
if (this.pool.workerNodes.length === 0) {
- this.nextWorkerNode
Id
= 0
- } else if (this.nextWorkerNode
Id
> this.pool.workerNodes.length - 1) {
- this.nextWorkerNode
Id
= this.pool.workerNodes.length - 1
+ this.nextWorkerNode
Key
= 0
+ } else if (this.nextWorkerNode
Key
> this.pool.workerNodes.length - 1) {
+ this.nextWorkerNode
Key
= this.pool.workerNodes.length - 1
}
}
return true
}
}
}
return true
}
+
+ private roundRobinNextWorkerNodeKey (): number {
+ this.nextWorkerNodeKey =
+ this.nextWorkerNodeKey === this.pool.workerNodes.length - 1
+ ? 0
+ : this.nextWorkerNodeKey + 1
+ return this.nextWorkerNodeKey
+ }
}
}