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:
parent
e244ccbe91
commit
eb2fc666c2
@ -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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user