X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fqueue.ts;h=86b69051174672a92c158317f84beb1874cebf07;hb=cdb517b318cd4f26b4895988ae8444d50945ddde;hp=7682f65f952136743c1f81724a26e53264ac18ed;hpb=e34f0ebcd2536e0890242ab414467c0e68ed65e6;p=poolifier.git diff --git a/src/queue.ts b/src/queue.ts index 7682f65f..86b69051 100644 --- a/src/queue.ts +++ b/src/queue.ts @@ -9,11 +9,13 @@ export class Queue { private items: Record private head: number private tail: number + private max: number public constructor () { this.items = {} this.head = 0 this.tail = 0 + this.max = 0 } /** @@ -26,6 +28,16 @@ export class Queue { return this.tail - this.head } + /** + * Get the maximum size of the queue. + * + * @returns The maximum size of the queue. + * @readonly + */ + public get maxSize (): number { + return this.max + } + /** * Enqueue an item. * @@ -35,6 +47,7 @@ export class Queue { public enqueue (item: T): number { this.items[this.tail] = item this.tail++ + if (this.size > this.max) this.max = this.size return this.size }