From d510b07aededd59443e877c4e7c7b6e2b9822dfe Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Fri, 26 Aug 2022 17:19:36 +0200 Subject: refactor(frontend): custom mutex implementation Lets us track priorities of tasks without cancellation. --- subprojects/frontend/src/utils/PendingTask.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'subprojects/frontend/src/utils/PendingTask.ts') diff --git a/subprojects/frontend/src/utils/PendingTask.ts b/subprojects/frontend/src/utils/PendingTask.ts index 205c8452..d0b24c1f 100644 --- a/subprojects/frontend/src/utils/PendingTask.ts +++ b/subprojects/frontend/src/utils/PendingTask.ts @@ -1,3 +1,4 @@ +import TimeoutError from './TimeoutError'; import getLogger from './getLogger'; const log = getLogger('utils.PendingTask'); @@ -15,16 +16,14 @@ export default class PendingTask { resolveCallback: (value: T) => void, rejectCallback: (reason?: unknown) => void, timeoutMs: number | undefined, - timeoutCallback: () => void | undefined, + timeoutCallback?: (() => void) | undefined, ) { this.resolveCallback = resolveCallback; this.rejectCallback = rejectCallback; this.timeout = setTimeout(() => { if (!this.resolved) { - this.reject(new Error('Request timed out')); - if (timeoutCallback) { - timeoutCallback(); - } + this.reject(new TimeoutError()); + timeoutCallback?.(); } }, timeoutMs); } -- cgit v1.2.3-54-g00ecf