mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Chore: update domain alive check
This commit is contained in:
23
Build/lib/keyed-async-mutex.ts
Normal file
23
Build/lib/keyed-async-mutex.ts
Normal 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;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user