Skip to content

Commit 7743ea3

Browse files
committed
refactor: implement AsyncIterable and Disposable interfaces in PQueue for improved functionality
Signed-off-by: Vladislav Polyakov <[email protected]>
1 parent 3e4c9b9 commit 7743ea3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/topic/src/queue.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export class PQueue<T> {
2-
private heap: { value: T; priority: number }[] = [];
1+
export class PQueue<T> implements AsyncIterable<T>, Disposable {
32
private closed = false;
4-
private pendingShifts: ((value: IteratorResult<T>) => void)[] = [];
5-
private pendingRejects: ((reason?: any) => void)[] = [];
3+
private readonly heap: { value: T; priority: number }[] = [];
4+
private readonly pendingShifts: ((value: IteratorResult<T>) => void)[] = [];
5+
private readonly pendingRejects: ((reason?: any) => void)[] = [];
66

77
get size(): number {
88
return this.heap.length;
@@ -96,4 +96,11 @@ export class PQueue<T> {
9696
yield value;
9797
}
9898
}
99+
100+
[Symbol.dispose]() {
101+
this.close();
102+
this.heap.length = 0;
103+
this.pendingShifts.length = 0;
104+
this.pendingRejects.length = 0;
105+
}
99106
}

0 commit comments

Comments
 (0)