Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -0,0 +1,32 @@
|
||||
export const WEB_READINESS_CACHE_TTL_MS = 1_000;
|
||||
|
||||
let cached:
|
||||
| {
|
||||
check: () => Promise<unknown>;
|
||||
expiresAt: number;
|
||||
pending: Promise<void>;
|
||||
}
|
||||
| undefined;
|
||||
|
||||
export function checkCachedWebReadiness(check: () => Promise<unknown>, now = Date.now()): Promise<void> {
|
||||
if (cached?.check === check && cached.expiresAt > now) {
|
||||
return cached.pending;
|
||||
}
|
||||
|
||||
let pending: Promise<void>;
|
||||
try {
|
||||
pending = Promise.resolve(check()).then(() => undefined);
|
||||
} catch (error) {
|
||||
pending = Promise.reject(error);
|
||||
}
|
||||
cached = {
|
||||
check,
|
||||
expiresAt: now + WEB_READINESS_CACHE_TTL_MS,
|
||||
pending,
|
||||
};
|
||||
return pending;
|
||||
}
|
||||
|
||||
export function resetWebReadinessCacheForTests(): void {
|
||||
cached = undefined;
|
||||
}
|
||||
Reference in new issue
Block a user