1
0
mirror of https://github.com/dzeiocom/libs.git synced 2025-04-23 03:12:12 +00:00

Added support to put multiple Promises in add

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2021-03-11 11:43:45 +01:00
parent e244ccbe91
commit eb2fc666c2
Signed by: Florian Bouillon
GPG Key ID: 50BD648F12C86AB6

View File

@ -20,7 +20,8 @@ export default class Queue {
this.queue = len this.queue = len
} }
public async add<T = any>(promise: Promise<T>) { public async add<T = any>(...promises: Array<Promise<T>>) {
for (const promise of promises) {
while (this.queue >= this.maxQueueLength || this.isPaused) { while (this.queue >= this.maxQueueLength || this.isPaused) {
await new Promise((res) => setTimeout(res, this.timeToWait)) await new Promise((res) => setTimeout(res, this.timeToWait))
} }
@ -33,6 +34,7 @@ export default class Queue {
this.throwError = e this.throwError = e
}) })
} }
}
public async waitEnd() { public async waitEnd() {
while (this.queue !== 0) { while (this.queue !== 0) {