fix(core): update
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/lik',
|
||||
version: '6.0.6',
|
||||
version: '6.0.7',
|
||||
description: 'light little helpers for node'
|
||||
}
|
||||
|
34
ts/backpressuredarray.ts
Normal file
34
ts/backpressuredarray.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import * as plugins from './lik.plugins.js';
|
||||
|
||||
export class BackpressuredArray<T> {
|
||||
private data: T[];
|
||||
private highWaterMark: number;
|
||||
public hasSpace: plugins.smartrx.rxjs.Subject<void>;
|
||||
|
||||
constructor(highWaterMark: number = 16) {
|
||||
this.data = [];
|
||||
this.highWaterMark = highWaterMark;
|
||||
this.hasSpace = new plugins.smartrx.rxjs.Subject<void>();
|
||||
}
|
||||
|
||||
push(item: T): boolean {
|
||||
this.data.push(item);
|
||||
const spaceAvailable = this.checkSpaceAvailable();
|
||||
if (spaceAvailable) {
|
||||
this.hasSpace.next();
|
||||
}
|
||||
return spaceAvailable
|
||||
}
|
||||
|
||||
shift(): T | undefined {
|
||||
const item = this.data.shift();
|
||||
if (this.checkSpaceAvailable()) {
|
||||
this.hasSpace.next();
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
checkSpaceAvailable(): boolean {
|
||||
return this.data.length < this.highWaterMark;
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
export * from './lik.asyncexecutionstack.js';
|
||||
export * from './backpressuredarray.js';
|
||||
export * from './lik.fastmap.js';
|
||||
export * from './lik.interestmap.js';
|
||||
export * from './lik.interestmap.interest.js';
|
||||
|
Reference in New Issue
Block a user