From 112dc6c7f1d247260da39a02d4b569774e154366 Mon Sep 17 00:00:00 2001 From: Devin Elrose Date: Tue, 2 Jan 2024 20:04:13 -0800 Subject: [PATCH] removes unnecessary bool, adds error handling --- libs/drawing-engine/src/engine/CallbackQueue.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libs/drawing-engine/src/engine/CallbackQueue.ts b/libs/drawing-engine/src/engine/CallbackQueue.ts index 449147d..6a1d553 100644 --- a/libs/drawing-engine/src/engine/CallbackQueue.ts +++ b/libs/drawing-engine/src/engine/CallbackQueue.ts @@ -1,6 +1,5 @@ export class CallbackQueue { private queue: Array<() => void | Promise> = [] - private isProcessing = false private promise: Promise | null = null public push(action: () => void | Promise) { @@ -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