import { Mutex } from 'async-mutex';
class MutexManager {
    mutex = new Mutex();
    mutexMap = new Map();
    async acquire(id) {
        const release = await this.mutex.acquire();
        try {
            const mutex = this.mutexMap.get(id) ?? new Mutex();
            if (!this.mutexMap.has(id))
                this.mutexMap.set(id, mutex);
            return await mutex.acquire();
        }
        finally {
            release();
        }
    }
}
export const mutexManager = new MutexManager();
//# sourceMappingURL=mutexManager.js.map