]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
refactor: cleanup async lock implementation
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 12 Aug 2025 21:41:26 +0000 (23:41 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 12 Aug 2025 21:41:26 +0000 (23:41 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/utils/AsyncLock.ts

index 49565046dda460d8fa12d87db67b451216c02969..8fad063b443ac8873d39a212dbea11a85d7b94ab 100644 (file)
@@ -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<void> {
+  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<void>(resolve => {
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      asyncLock.resolveQueue.dequeue()!()
-      resolve()
-    })
+    asyncLock.acquired = false
   }
 }