1
0
mirror of https://github.com/dzeiocom/libs.git synced 2025-04-22 19:02:14 +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,18 +20,20 @@ export default class Queue {
this.queue = len
}
public async add<T = any>(promise: Promise<T>) {
while (this.queue >= this.maxQueueLength || this.isPaused) {
await new Promise((res) => setTimeout(res, this.timeToWait))
public async add<T = any>(...promises: Array<Promise<T>>) {
for (const promise of promises) {
while (this.queue >= this.maxQueueLength || this.isPaused) {
await new Promise((res) => setTimeout(res, this.timeToWait))
}
this.updateCurrentQueueLength(this.queue+1)
promise
.then(() => {
this.updateCurrentQueueLength(this.queue-1)
}).catch((e) => {
this.updateCurrentQueueLength(this.queue-1)
this.throwError = e
})
}
this.updateCurrentQueueLength(this.queue+1)
promise
.then(() => {
this.updateCurrentQueueLength(this.queue-1)
}).catch((e) => {
this.updateCurrentQueueLength(this.queue-1)
this.throwError = e
})
}
public async waitEnd() {