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 () => {