Compare commits

..

14 Commits

Author SHA1 Message Date
052322fb98 6.0.13 2024-02-23 17:44:52 +01:00
9e1eb0b3a0 fix(core): update 2024-02-23 17:44:51 +01:00
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
326030456f 6.0.8 2023-11-13 14:59:04 +01:00
184dc98127 fix(core): update 2023-11-13 14:59:03 +01:00
702ce00288 6.0.7 2023-11-13 14:40:02 +01:00
ff0d745170 fix(core): update 2023-11-13 14:40:01 +01:00
5 changed files with 70 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@push.rocks/lik", "name": "@push.rocks/lik",
"version": "6.0.6", "version": "6.0.13",
"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",

6
pnpm-lock.yaml generated
View File

@ -1846,7 +1846,7 @@ packages:
'@web/parse5-utils': 2.1.0 '@web/parse5-utils': 2.1.0
chokidar: 3.5.3 chokidar: 3.5.3
clone: 2.1.2 clone: 2.1.2
es-module-lexer: 1.3.1 es-module-lexer: 1.4.1
get-stream: 6.0.1 get-stream: 6.0.1
is-stream: 2.0.1 is-stream: 2.0.1
isbinaryfile: 5.0.0 isbinaryfile: 5.0.0
@ -2891,6 +2891,10 @@ packages:
resolution: {integrity: sha512-JUFAyicQV9mXc3YRxPnDlrfBKpqt6hUYzz9/boprUJHs4e4KVr3XwOF70doO6gwXUor6EWZJAyWAfKki84t20Q==} resolution: {integrity: sha512-JUFAyicQV9mXc3YRxPnDlrfBKpqt6hUYzz9/boprUJHs4e4KVr3XwOF70doO6gwXUor6EWZJAyWAfKki84t20Q==}
dev: true dev: true
/es-module-lexer@1.4.1:
resolution: {integrity: sha512-cXLGjP0c4T3flZJKQSuziYoq7MlT+rnvfZjfp7h+I7K9BNX54kP9nyWvdbwjQ4u1iWbOL4u96fgeZLToQlZC7w==}
dev: true
/es-set-tostringtag@2.0.2: /es-set-tostringtag@2.0.2:
resolution: {integrity: sha512-BuDyupZt65P9D2D2vA/zqcI3G5xRsklm5N3xCwuiy+/vKy8i0ifdsQP1sLgO4tZDSCaQUSnmC48khknGMV3D2Q==} resolution: {integrity: sha512-BuDyupZt65P9D2D2vA/zqcI3G5xRsklm5N3xCwuiy+/vKy8i0ifdsQP1sLgO4tZDSCaQUSnmC48khknGMV3D2Q==}
engines: {node: '>= 0.4'} engines: {node: '>= 0.4'}

View File

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

62
ts/backpressuredarray.ts Normal file
View File

@ -0,0 +1,62 @@
import * as plugins from './lik.plugins.js';
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 = [];
this.highWaterMark = highWaterMark;
}
push(item: T): boolean {
this.data.push(item);
this.itemsAvailable.next('itemsAvailable');
const spaceAvailable = this.checkSpaceAvailable();
if (spaceAvailable) {
this.hasSpace.next('hasSpace');
}
return spaceAvailable;
}
shift(): T | undefined {
const item = this.data.shift();
if (this.checkSpaceAvailable()) {
this.hasSpace.next('hasSpace');
}
return item;
}
checkSpaceAvailable(): boolean {
return this.data.length < this.highWaterMark;
}
waitForSpace(): Promise<void> {
return new Promise<void>((resolve) => {
if (this.checkSpaceAvailable()) {
resolve();
} else {
const subscription = this.hasSpace.subscribe(() => {
subscription.unsubscribe();
resolve();
});
}
});
}
waitForItems(): Promise<void> {
return new Promise<void>((resolve) => {
if (this.data.length > 0) {
resolve();
} else {
const subscription = this.itemsAvailable.subscribe(() => {
subscription.unsubscribe();
resolve();
});
}
});
}
}

View File

@ -1,4 +1,5 @@
export * from './lik.asyncexecutionstack.js'; export * from './lik.asyncexecutionstack.js';
export * from './backpressuredarray.js';
export * from './lik.fastmap.js'; export * from './lik.fastmap.js';
export * from './lik.interestmap.js'; export * from './lik.interestmap.js';
export * from './lik.interestmap.interest.js'; export * from './lik.interestmap.interest.js';