import { Mutex, withTimeout } from "async-mutex";

//#region lib/util/mutex.ts
const DEFAULT_NAMESPACE = "default";
let mutexes = {};
function initMutexes() {
	mutexes = {};
}
function getMutex(key, namespace = DEFAULT_NAMESPACE) {
	mutexes[namespace] ??= {};
	mutexes[namespace][key] ??= withTimeout(new Mutex(), 1e3 * 60 * 2);
	return mutexes[namespace][key];
}
function acquireLock(key, namespace = DEFAULT_NAMESPACE) {
	return getMutex(key, namespace).acquire();
}

//#endregion
export { acquireLock, initMutexes };
//# sourceMappingURL=mutex.js.map