remove unnecessary withCacheAsync
This commit is contained in:
@@ -22,25 +22,6 @@ export function withCache<T, U extends (...args: Parameters<U>) => T>(
|
||||
};
|
||||
}
|
||||
|
||||
export function withCacheAsync<
|
||||
T,
|
||||
U extends (...args: Parameters<U>) => Promise<T>,
|
||||
>(
|
||||
fn: U,
|
||||
cache: Cache<Promise<T>>,
|
||||
): (key: unknown, ...args: Parameters<U>) => Promise<T> {
|
||||
return async (key, ...args) => {
|
||||
if (cache.has(key)) {
|
||||
return (await cache.get(key)) as T;
|
||||
}
|
||||
|
||||
const value = fn(...args);
|
||||
cache.set(key, value);
|
||||
|
||||
return await value;
|
||||
};
|
||||
}
|
||||
|
||||
export function memoize<T, U>(fn: (arg: U) => T): [(arg: U) => T, Cache<T>] {
|
||||
const cache = new Map<unknown, T>();
|
||||
const callback = withCache(fn, cache);
|
||||
|
||||
Reference in New Issue
Block a user