X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Futils%2FAsyncLock.ts;h=f6b793a60748beaa8454fdb80e13510553a25898;hb=452a4864d4a8d0286ddd351958d8cc02574b4ba9;hp=d11419723c010fef52739b53f4ce86009103cb08;hpb=95e03ad147e276c61b03ab84902349dfe5084396;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/AsyncLock.ts b/src/utils/AsyncLock.ts index d1141972..f6b793a6 100644 --- a/src/utils/AsyncLock.ts +++ b/src/utils/AsyncLock.ts @@ -1,12 +1,12 @@ -// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2024. All Rights Reserved. -import Queue from 'mnemonist/queue.js' +import { Queue } from 'mnemonist' import { Constants } from './Constants.js' export enum AsyncLockType { configuration = 'configuration', - performance = 'performance', + performance = 'performance' } type ResolveType = (value: void | PromiseLike) => void @@ -18,7 +18,6 @@ export class AsyncLock { private constructor () { this.acquired = false - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment this.resolveQueue = new Queue() } @@ -36,23 +35,20 @@ export class AsyncLock { asyncLock.acquired = true return } - await new Promise((resolve) => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access + await new Promise(resolve => { asyncLock.resolveQueue.enqueue(resolve) }) } private static async release (type: AsyncLockType): Promise { const asyncLock = AsyncLock.getAsyncLock(type) - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access if (asyncLock.resolveQueue.size === 0 && asyncLock.acquired) { asyncLock.acquired = false return } - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const queuedResolve = asyncLock.resolveQueue.dequeue()! - await new Promise((resolve) => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call + await new Promise(resolve => { queuedResolve() resolve() })