Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
af9b045d31 | |||
d7718d4340 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@push.rocks/lik",
|
||||
"version": "6.0.11",
|
||||
"version": "6.0.12",
|
||||
"private": false,
|
||||
"description": "light little helpers for node",
|
||||
"main": "dist_ts/index.js",
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/lik',
|
||||
version: '6.0.11',
|
||||
version: '6.0.12',
|
||||
description: 'light little helpers for node'
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ export class BackpressuredArray<T> {
|
||||
public data: T[];
|
||||
private highWaterMark: number;
|
||||
public hasSpace = new plugins.smartrx.rxjs.Subject<'hasSpace'>();
|
||||
private itemsAvailable = new plugins.smartrx.rxjs.Subject<'itemsAvailable'>();
|
||||
|
||||
constructor(highWaterMark: number = 16) {
|
||||
this.data = [];
|
||||
@ -12,11 +13,13 @@ export class BackpressuredArray<T> {
|
||||
|
||||
push(item: T): boolean {
|
||||
this.data.push(item);
|
||||
this.itemsAvailable.next('itemsAvailable');
|
||||
|
||||
const spaceAvailable = this.checkSpaceAvailable();
|
||||
if (spaceAvailable) {
|
||||
this.hasSpace.next('hasSpace');
|
||||
}
|
||||
return spaceAvailable
|
||||
return spaceAvailable;
|
||||
}
|
||||
|
||||
shift(): T | undefined {
|
||||
@ -43,4 +46,18 @@ export class BackpressuredArray<T> {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// New method to wait for items
|
||||
waitForItems(): Promise<void> {
|
||||
return new Promise<void>((resolve) => {
|
||||
if (this.data.length > 0) {
|
||||
resolve();
|
||||
} else {
|
||||
const subscription = this.itemsAvailable.subscribe(() => {
|
||||
subscription.unsubscribe();
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user