import { symbol } from './once'; export function onceAsync( fn: () => Promise, thisArg?: any ): () => Promise { let value: T | Promise | typeof symbol = symbol; const awaiter = async () => { try { value = await value; } catch { value = symbol; } }; const cfn = async (): Promise => { if (value === symbol) { value = fn.call(thisArg); setTimeout(awaiter); } return value as T | Promise; }; return cfn; } export default onceAsync; Object.defineProperties(onceAsync, { default: { get: () => onceAsync }, onceAsync: { get: () => onceAsync }, });