X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fqueue.ts;h=ead4b6375388398483eda10abaaae50e2c779928;hb=715143510b6627ffeb2735f42bb682935f16b9e9;hp=8b761c8ff82d5ca7c0c0a67b361188d1fda19dc5;hpb=116a8c861a8a7c5b348b848f1409e1b68dd82699;p=poolifier.git diff --git a/src/queue.ts b/src/queue.ts index 8b761c8f..ead4b637 100644 --- a/src/queue.ts +++ b/src/queue.ts @@ -6,18 +6,15 @@ * @typeParam T - Type of queue items. */ export class Queue { - private items: T[] - private offset: number - public size: number - public maxSize: number + private items!: T[] + private offset!: number + /** The size of the queue. */ + public size!: number + /** The maximum size of the queue. */ + public maxSize!: number public constructor () { - this.items = [] - /** The size of the queue. */ - this.size = 0 - this.offset = 0 - /** The maximum size of the queue. */ - this.maxSize = 0 + this.clear() } /** @@ -54,7 +51,7 @@ export class Queue { } /** - * Peek at the first item. + * Peeks at the first item. * * @returns The first item or `undefined` if the queue is empty. */ @@ -64,4 +61,14 @@ export class Queue { } return this.items[this.offset] } + + /** + * Clears the queue. + */ + public clear (): void { + this.items = [] + this.offset = 0 + this.size = 0 + this.maxSize = 0 + } }