feat: improve deployment workflows
This commit is contained in:
+8
-7
@@ -41,15 +41,16 @@ export function ctx() {
|
||||
return store;
|
||||
}
|
||||
|
||||
const cache: Record<string, unknown> = {};
|
||||
export function createCachedGetter<T>(
|
||||
key: string,
|
||||
_key: string,
|
||||
fn: () => Promise<T>,
|
||||
): () => Promise<T> {
|
||||
return async () => {
|
||||
if (key in cache) return cache[key] as T;
|
||||
const result = await fn();
|
||||
cache[key] = result;
|
||||
return result;
|
||||
let cached: Promise<T> | undefined;
|
||||
return () => {
|
||||
cached ??= fn().catch((error) => {
|
||||
cached = undefined;
|
||||
throw error;
|
||||
});
|
||||
return cached;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user