1
0
mirror of https://github.com/dzeiocom/libs.git synced 2025-04-22 19:02:14 +00:00

Added error throwing

Signed-off-by: Florian Bouillon <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2020-07-31 10:53:26 +02:00
parent ed51c55fa3
commit 1a6f318400

View File

@ -1,6 +1,7 @@
export default class Queue {
private queue = 0
private isPaused = false
private throwError?: Error
public constructor(
private maxQueueLength = 5,
@ -27,13 +28,17 @@ export default class Queue {
promise
.then(() => {
this.updateCurrentQueueLength(this.queue-1)
}).catch(() => {
}).catch((e) => {
this.updateCurrentQueueLength(this.queue-1)
this.throwError = e
})
}
public async waitEnd() {
while (this.queue !== 0) {
if (this.throwError) {
throw this.throwError
}
await new Promise((res) => setTimeout(res, this.timeToWait))
}
}