Compare commits

..

8 Commits

Author SHA1 Message Date
af9b045d31 6.0.12 2023-11-13 17:20:46 +01:00
d7718d4340 fix(core): update 2023-11-13 17:20:45 +01:00
92592d9e9a 6.0.11 2023-11-13 16:44:39 +01:00
a786c43970 fix(core): update 2023-11-13 16:44:38 +01:00
66658dc877 6.0.10 2023-11-13 16:43:07 +01:00
be78d74124 fix(core): update 2023-11-13 16:43:06 +01:00
bde0404777 6.0.9 2023-11-13 16:27:05 +01:00
dfe973f5d8 fix(core): update 2023-11-13 16:27:04 +01:00
3 changed files with 24 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@push.rocks/lik", "name": "@push.rocks/lik",
"version": "6.0.8", "version": "6.0.12",
"private": false, "private": false,
"description": "light little helpers for node", "description": "light little helpers for node",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/lik', name: '@push.rocks/lik',
version: '6.0.8', version: '6.0.12',
description: 'light little helpers for node' description: 'light little helpers for node'
} }

View File

@ -1,29 +1,31 @@
import * as plugins from './lik.plugins.js'; import * as plugins from './lik.plugins.js';
export class BackpressuredArray<T> { export class BackpressuredArray<T> {
private data: T[]; public data: T[];
private highWaterMark: number; private highWaterMark: number;
public hasSpace: plugins.smartrx.rxjs.Subject<void>; public hasSpace = new plugins.smartrx.rxjs.Subject<'hasSpace'>();
private itemsAvailable = new plugins.smartrx.rxjs.Subject<'itemsAvailable'>();
constructor(highWaterMark: number = 16) { constructor(highWaterMark: number = 16) {
this.data = []; this.data = [];
this.highWaterMark = highWaterMark; this.highWaterMark = highWaterMark;
this.hasSpace = new plugins.smartrx.rxjs.Subject<void>();
} }
push(item: T): boolean { push(item: T): boolean {
this.data.push(item); this.data.push(item);
this.itemsAvailable.next('itemsAvailable');
const spaceAvailable = this.checkSpaceAvailable(); const spaceAvailable = this.checkSpaceAvailable();
if (spaceAvailable) { if (spaceAvailable) {
this.hasSpace.next(); this.hasSpace.next('hasSpace');
} }
return spaceAvailable return spaceAvailable;
} }
shift(): T | undefined { shift(): T | undefined {
const item = this.data.shift(); const item = this.data.shift();
if (this.checkSpaceAvailable()) { if (this.checkSpaceAvailable()) {
this.hasSpace.next(); this.hasSpace.next('hasSpace');
} }
return item; return item;
} }
@ -44,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();
});
}
});
}
} }