3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Add .length to Queue

This commit is contained in:
Dragory 2021-05-22 13:46:55 +03:00
parent b254022db2
commit 0ea1ab4b46
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -14,6 +14,16 @@ export class Queue<TQueueFunction extends AnyFn = AnyFn> {
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<void> {
const promise = new Promise<void>(resolve => {
this.queue.push(async () => {