Improve fs memo (hash xxhash64)

This commit is contained in:
SukkaW
2024-10-18 12:05:41 +08:00
parent 4c1c237fc3
commit 113eae281f
2 changed files with 18 additions and 6 deletions

View File

@@ -1,6 +1,10 @@
const notError = Symbol('notError');
export function createMemoizedPromise<T>(fn: () => Promise<T>, preload = true): () => Promise<T> {
export function createMemoizedPromise<T>(
fn: () => Promise<T>,
/** whether to create promise immediately or only create after first access */
preload = true
): () => Promise<T> {
let error: Error | typeof notError = notError;
let promise: Promise<T> | null = preload