type AsyncCallback = () => Promise; export const createAsyncProxy = (asyncCallback: AsyncCallback): AsyncCallback => { let promise: Promise | null = null; return async (): Promise => { if (promise) { return promise; } try { promise = asyncCallback(); return await promise; } finally { promise = null; } }; };