feat(collections): add new collection APIs, iterator support, and tree serialization utilities
This commit is contained in:
@@ -12,6 +12,10 @@ export class BackpressuredArray<T> {
|
||||
this.highWaterMark = highWaterMark;
|
||||
}
|
||||
|
||||
public get length(): number {
|
||||
return this.data.length;
|
||||
}
|
||||
|
||||
push(item: T): boolean {
|
||||
this.data.push(item);
|
||||
this.itemsAvailable.next('itemsAvailable');
|
||||
@@ -23,6 +27,13 @@ export class BackpressuredArray<T> {
|
||||
return spaceAvailable;
|
||||
}
|
||||
|
||||
pushMany(items: T[]): boolean {
|
||||
for (const item of items) {
|
||||
this.push(item);
|
||||
}
|
||||
return this.checkSpaceAvailable();
|
||||
}
|
||||
|
||||
shift(): T | undefined {
|
||||
const item = this.data.shift();
|
||||
if (this.checkSpaceAvailable()) {
|
||||
@@ -31,6 +42,10 @@ export class BackpressuredArray<T> {
|
||||
return item;
|
||||
}
|
||||
|
||||
peek(): T | undefined {
|
||||
return this.data[0];
|
||||
}
|
||||
|
||||
checkSpaceAvailable(): boolean {
|
||||
return this.data.length < this.highWaterMark;
|
||||
}
|
||||
@@ -75,6 +90,10 @@ export class BackpressuredArray<T> {
|
||||
});
|
||||
}
|
||||
|
||||
public [Symbol.iterator](): Iterator<T> {
|
||||
return this.data[Symbol.iterator]();
|
||||
}
|
||||
|
||||
/**
|
||||
* destroys the BackpressuredArray, completing all subjects
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user