From 0ea1ab4b464b66d48c26e47e8a970e645729877f Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sat, 22 May 2021 13:46:55 +0300 Subject: [PATCH] Add .length to Queue --- backend/src/Queue.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/src/Queue.ts b/backend/src/Queue.ts index 3158346b..cf507a22 100644 --- a/backend/src/Queue.ts +++ b/backend/src/Queue.ts @@ -14,6 +14,16 @@ export class Queue { this.timeout = timeout; } + /** + * The number of operations that are currently queued up or running. + * I.e. backlog (queue) + current running process, if any. + * + * If this is 0, queueing a function will run it as soon as possible. + */ + get length(): number { + return this.queue.length + (this.running ? 1 : 0); + } + public add(fn: TQueueFunction): Promise { const promise = new Promise(resolve => { this.queue.push(async () => {