MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / execWithMutex

Function execWithMutex

panel/src/app/utils/sync.ts:6–19  ·  view source on GitHub ↗
(fn: () => Promise<T>)

Source from the content-addressed store, hash-verified

4export const mutexIdMap = new Map<string, Mutex>();
5
6export async function execWithMutex<T>(fn: () => Promise<T>): Promise<T> {
7 let mutex = mutexMap.get(fn);
8 if (!mutex) {
9 mutex = new Mutex();
10 mutexMap.set(fn, mutex);
11 }
12 const releaseLock = await mutex.acquire();
13 try {
14 return await fn();
15 } finally {
16 releaseLock();
17 mutexMap.delete(fn);
18 }
19}
20
21export async function execWithMutexId<T>(id: string, fn: () => Promise<T>) {
22 let mutex = mutexIdMap.get(id);

Callers

nothing calls this directly

Calls 4

fnFunction · 0.85
deleteMethod · 0.65
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected