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:
parent
e244ccbe91
commit
eb2fc666c2
@ -20,18 +20,20 @@ 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>>) {
|
||||||
while (this.queue >= this.maxQueueLength || this.isPaused) {
|
for (const promise of promises) {
|
||||||
await new Promise((res) => setTimeout(res, this.timeToWait))
|
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() {
|
public async waitEnd() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user