Skip to content

Commit

Permalink
removes unnecessary bool, adds error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenist committed Jan 3, 2024
1 parent 206e3bf commit 112dc6c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions libs/drawing-engine/src/engine/CallbackQueue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export class CallbackQueue {
private queue: Array<() => void | Promise<void>> = []
private isProcessing = false
private promise: Promise<void> | null = null

public push(action: () => void | Promise<void>) {
Expand All @@ -9,19 +8,19 @@ export class CallbackQueue {
}

private async processQueue() {
if (this.isProcessing) {
return this.promise
}
await this.promise
this.promise = new Promise(async (resolve) => {
this.isProcessing = true
while (this.queue.length > 0) {
const action = this.queue.shift()
if (!action) {
return
}
await Promise.resolve(action())
try {
await Promise.resolve(action())
} catch (e) {
console.error(e)
}
}
this.isProcessing = false
resolve()
})
return this.promise
Expand Down

0 comments on commit 112dc6c

Please sign in to comment.