Skip to content

Commit 437d8f0

Browse files
committed
Use array of struct instead of two arrays
1 parent 2a68b72 commit 437d8f0

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

JavaScript/2-timeouts.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class Queue {
55
this.concurrency = concurrency;
66
this.count = 0;
77
this.waiting = [];
8-
this.waitingStart = [];
98
this.onProcess = null;
109
this.onDone = null;
1110
this.onSuccess = null;
@@ -31,8 +30,7 @@ class Queue {
3130
this.next(task);
3231
return;
3332
}
34-
this.waiting.push(task);
35-
this.waitingStart.push(Date.now());
33+
this.waiting.push({ task, start: Date.now() });
3634
}
3735
next(task) {
3836
this.count++;
@@ -54,9 +52,8 @@ class Queue {
5452
onProcess(task, finish);
5553
}
5654
takeNext() {
57-
const { waiting, waitingStart, waitTimeout } = this;
58-
const task = waiting.shift();
59-
const start = waitingStart.shift();
55+
const { waiting, waitTimeout } = this;
56+
const { task, start } = waiting.shift();
6057
if (waitTimeout !== Infinity) {
6158
const delay = Date.now() - start;
6259
if (delay > waitTimeout) {

0 commit comments

Comments
 (0)