mirror of
https://github.com/louislam/dockge.git
synced 2025-08-09 22:57:48 +02:00
Init (#1)
This commit is contained in:
24
backend/utils/limit-queue.ts
Normal file
24
backend/utils/limit-queue.ts
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user