From: Jérôme Benoit Date: Thu, 4 May 2023 22:35:59 +0000 (+0200) Subject: Merge branch 'master' of github.com:poolifier/poolifier X-Git-Tag: v2.4.12~20 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3db6a2b42ee697b6f587b0f41020771941a65e68;hp=3a592a1254b999797590d1b54662b747eed17528;p=poolifier.git Merge branch 'master' of github.com:poolifier/poolifier --- diff --git a/.eslintrc.js b/.eslintrc.js index 58450447..d7004cc5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -49,6 +49,7 @@ module.exports = defineConfig({ 'ctx', 'deprecations', 'dequeue', + 'dequeued', 'ecma', 'enqueue', 'enum', diff --git a/src/queue.ts b/src/queue.ts index 35f9025e..a2a61381 100644 --- a/src/queue.ts +++ b/src/queue.ts @@ -2,6 +2,8 @@ /** * Queue + * + * @typeParam T - Type of queue items. */ export class Queue { private items: Record @@ -14,16 +16,34 @@ export class Queue { this.tail = 0 } + /** + * Get the size of the queue. + * + * @returns The size of the queue. + * @readonly + */ public get size (): number { return this.tail - this.head } + /** + * Enqueue an item. + * + * @param item - Item to enqueue. + * @returns The new size of the queue. + */ public enqueue (item: T): number { this.items[this.tail] = item this.tail++ return this.size } + /** + * Dequeue an item. + * + * @returns The dequeued item. + * @returns `undefined` if the queue is empty. + */ public dequeue (): T | undefined { if (this.size <= 0) return undefined const item = this.items[this.head]