Skip to content

Commit

Permalink
fix: ArrayQueue iterator logic
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Apr 9, 2024
2 parents 7090328 + 878ae8a commit 9a3c75d
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions lib/util/ArrayQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,18 @@ class ArrayQueue {
}

[Symbol.iterator]() {
let i = -1;
let reversed = false;
return {
next: () => {
if (!reversed) {
i++;
if (i < this._list.length) {
return {
done: false,
value: this._list[i]
};
}
reversed = true;
i = this._listReversed.length;
}
i--;
if (i < 0) {
const item = this.dequeue();
if (item) {
return {
done: true,
value: undefined
done: false,
value: item
};
}
return {
done: false,
value: this._listReversed[i]
done: true,
value: undefined
};
}
};
Expand Down

0 comments on commit 9a3c75d

Please sign in to comment.