(id: string, fn: () => Promise<T>)
| 19 | } |
| 20 | |
| 21 | export async function execWithMutexId<T>(id: string, fn: () => Promise<T>) { |
| 22 | let mutex = mutexIdMap.get(id); |
| 23 | if (!mutex) { |
| 24 | mutex = new Mutex(); |
| 25 | mutexIdMap.set(id, mutex); |
| 26 | } |
| 27 | const releaseLock = await mutex.acquire(); |
| 28 | try { |
| 29 | return await fn(); |
| 30 | } finally { |
| 31 | releaseLock(); |
| 32 | mutexIdMap.delete(id); |
| 33 | } |
| 34 | } |
no test coverage detected