mirror of
https://github.com/louislam/dockge.git
synced 2024-11-27 21:24:02 +00:00
24 lines
501 B
TypeScript
24 lines
501 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 = null;
|
|
|
|
constructor(limit: number) {
|
|
super();
|
|
this.__limit = limit;
|
|
}
|
|
|
|
push(value : T) {
|
|
super.push(value);
|
|
if (this.length > this.__limit) {
|
|
const item = this.shift();
|
|
if (this.__onExceed) {
|
|
this.__onExceed(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|