import { WrappingDec } from "./utils"; /** * Decorates an async function that should only be called once. * Highly similar to Memoize, but clears state if the promise throws. */ export const PromiseOnce = WrappingDec((f: (...args: any[]) => Promise | T) => { let currentPromise: Promise = null; return function () { if (currentPromise) return currentPromise; const rawPromise = (async () => await f.call(this))(); rawPromise.catch((e) => { currentPromise = null; }) // currentPromise = fromPromise(rawPromise); currentPromise = rawPromise; return currentPromise; } })