export function memoizeAsync( fn: () => Promise, ): (() => Promise) & { invalidate: () => void } { let cached: { value: T } | undefined const wrapper = async (): Promise => { if (cached) return cached.value const value = await fn() cached = { value } return value } wrapper.invalidate = () => { cached = undefined } return wrapper }