Chore: update domain alive check

This commit is contained in:
SukkaW
2025-05-16 23:25:09 +08:00
parent bcf6244e1e
commit 803e503a1e
4 changed files with 165 additions and 203 deletions

View File

@@ -0,0 +1,23 @@
const globalMap = new Map<string, Map<string, Promise<unknown>>>();
export function createKeyedAsyncMutex(globalNamespaceKey: string) {
let map;
if (globalMap.has(globalNamespaceKey)) {
map = globalMap.get(globalNamespaceKey)!;
} else {
map = new Map();
globalMap.set(globalNamespaceKey, map);
}
return {
async acquire<T = unknown>(key: string, fn: () => Promise<T>) {
if (map.has(key)) {
return map.get(key);
}
const promise = fn();
map.set(key, promise);
return promise;
}
};
}