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:
parent
ed51c55fa3
commit
1a6f318400
@ -1,6 +1,7 @@
|
|||||||
export default class Queue {
|
export default class Queue {
|
||||||
private queue = 0
|
private queue = 0
|
||||||
private isPaused = false
|
private isPaused = false
|
||||||
|
private throwError?: Error
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private maxQueueLength = 5,
|
private maxQueueLength = 5,
|
||||||
@ -27,13 +28,17 @@ export default class Queue {
|
|||||||
promise
|
promise
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.updateCurrentQueueLength(this.queue-1)
|
this.updateCurrentQueueLength(this.queue-1)
|
||||||
}).catch(() => {
|
}).catch((e) => {
|
||||||
this.updateCurrentQueueLength(this.queue-1)
|
this.updateCurrentQueueLength(this.queue-1)
|
||||||
|
this.throwError = e
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async waitEnd() {
|
public async waitEnd() {
|
||||||
while (this.queue !== 0) {
|
while (this.queue !== 0) {
|
||||||
|
if (this.throwError) {
|
||||||
|
throw this.throwError
|
||||||
|
}
|
||||||
await new Promise((res) => setTimeout(res, this.timeToWait))
|
await new Promise((res) => setTimeout(res, this.timeToWait))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user