From 2e719408cec263020d66d056d63579b154524eb4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 12 Aug 2025 23:41:26 +0200 Subject: [PATCH] refactor: cleanup async lock implementation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/utils/AsyncLock.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/utils/AsyncLock.ts b/src/utils/AsyncLock.ts index 49565046..8fad063b 100644 --- a/src/utils/AsyncLock.ts +++ b/src/utils/AsyncLock.ts @@ -30,7 +30,7 @@ export class AsyncLock { return fn() as T } } finally { - await AsyncLock.release(type) + AsyncLock.release(type) } } @@ -53,16 +53,13 @@ export class AsyncLock { return AsyncLock.asyncLocks.get(type)! } - private static async release (type: AsyncLockType): Promise { + private static release (type: AsyncLockType): void { const asyncLock = AsyncLock.getAsyncLock(type) - if (asyncLock.resolveQueue.size === 0 && asyncLock.acquired) { - asyncLock.acquired = false + const nextResolve = asyncLock.resolveQueue.dequeue() + if (nextResolve != null) { + nextResolve() return } - await new Promise(resolve => { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - asyncLock.resolveQueue.dequeue()!() - resolve() - }) + asyncLock.acquired = false } } -- 2.43.0