Skip to content

Commit 4af527e

Browse files
committed
refactor: code cleanups
Signed-off-by: Jérôme Benoit <[email protected]>
1 parent f0c32db commit 4af527e

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

src/pools/abstract-pool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ export abstract class AbstractPool<
838838
this.checkMessageWorkerId(message)
839839
if (message.taskFunctionOperationStatus != null) {
840840
responsesReceived.push(message)
841-
if (responsesReceived.length === this.workerNodes.length) {
841+
if (responsesReceived.length >= this.workerNodes.length) {
842842
if (
843843
responsesReceived.every(
844844
(msg) => msg.taskFunctionOperationStatus === true,

src/pools/selection-strategies/abstract-worker-choice-strategy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ export abstract class AbstractWorkerChoiceStrategy<
124124
workerNodeKey: number | undefined,
125125
): number | undefined {
126126
if (
127-
workerNodeKey != null &&
128-
(workerNodeKey < 0 || !this.isWorkerNodeReady(workerNodeKey))
127+
workerNodeKey == null ||
128+
workerNodeKey < 0 ||
129+
workerNodeKey >= this.pool.workerNodes.length
129130
) {
130131
return undefined
131132
}

src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
149149
(this.nextWorkerNodeKey - 1 + this.pool.workerNodes.length) %
150150
this.pool.workerNodes.length
151151
}
152+
if (this.workerNodeId >= workerNodeKey) {
153+
this.workerNodeId =
154+
(this.workerNodeId - 1 + this.pool.workerNodes.length) %
155+
this.pool.workerNodes.length
156+
}
152157
return true
153158
}
154159

src/pools/selection-strategies/round-robin-worker-choice-strategy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export class RoundRobinWorkerChoiceStrategy<
4242
public choose(): number | undefined {
4343
this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
4444
this.roundRobinNextWorkerNodeKey()
45+
if (!this.isWorkerNodeReady(this.nextWorkerNodeKey!)) {
46+
return undefined
47+
}
4548
return this.checkWorkerNodeKey(this.nextWorkerNodeKey)
4649
}
4750

@@ -57,6 +60,9 @@ export class RoundRobinWorkerChoiceStrategy<
5760
this.nextWorkerNodeKey =
5861
(this.nextWorkerNodeKey - 1 + this.pool.workerNodes.length) %
5962
this.pool.workerNodes.length
63+
if (this.previousWorkerNodeKey >= workerNodeKey) {
64+
this.previousWorkerNodeKey = this.nextWorkerNodeKey
65+
}
6066
}
6167
return true
6268
}

src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
6868
public choose(): number | undefined {
6969
this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
7070
this.weightedRoundRobinNextWorkerNodeKey()
71+
if (!this.isWorkerNodeReady(this.nextWorkerNodeKey!)) {
72+
return undefined
73+
}
7174
return this.checkWorkerNodeKey(this.nextWorkerNodeKey)
7275
}
7376

@@ -86,6 +89,9 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
8689
this.nextWorkerNodeKey =
8790
(this.nextWorkerNodeKey - 1 + this.pool.workerNodes.length) %
8891
this.pool.workerNodes.length
92+
if (this.previousWorkerNodeKey >= workerNodeKey) {
93+
this.previousWorkerNodeKey = this.nextWorkerNodeKey
94+
}
8995
}
9096
return true
9197
}

src/queues/abstract-fixed-queue.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ export abstract class AbstractFixedQueue<T> implements IFixedQueue<T> {
7272
}
7373
}
7474
if (logicalIndex !== -1) {
75-
let physicalShiftIndex = this.start + logicalIndex
76-
if (physicalShiftIndex >= this.capacity) {
77-
physicalShiftIndex -= this.capacity
75+
if (logicalIndex === this.size - 1) {
76+
this.nodeArray[currentPhysicalIndex] = undefined
77+
--this.size
78+
return true
7879
}
80+
let physicalShiftIndex = currentPhysicalIndex
7981
for (let i = logicalIndex; i < this.size - 1; i++) {
8082
let nextPhysicalIndex = physicalShiftIndex + 1
8183
if (nextPhysicalIndex === this.capacity) {

0 commit comments

Comments
 (0)