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
|
||||
}
|
||||
|
||||
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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user