mirror of
https://github.com/louislam/dockge.git
synced 2024-11-24 17:23:28 +01:00
53b052c1e5
* Check Typescript * Fix backend typescript issues * Update
25 lines
532 B
TypeScript
25 lines
532 B
TypeScript
/**
|
|
* Limit Queue
|
|
* The first element will be removed when the length exceeds the limit
|
|
*/
|
|
export class LimitQueue<T> extends Array<T> {
|
|
__limit;
|
|
__onExceed? : (item : T | undefined) => void;
|
|
|
|
constructor(limit: number) {
|
|
super();
|
|
this.__limit = limit;
|
|
}
|
|
|
|
pushItem(value : T) {
|
|
super.push(value);
|
|
if (this.length > this.__limit) {
|
|
const item = this.shift();
|
|
if (this.__onExceed) {
|
|
this.__onExceed(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|