// lets you wait until it is uncorked by someone before running export default class DedupAwaiter { private promise: Promise | null; constructor( private func: () => Promise ) {} public async callOrDedup(): Promise { if (!this.promise) { this.promise = new Promise(async (resolve) => { resolve(await this.func()); }); } let promise = this.promise; let result = await promise; if (promise === this.promise) { this.promise = null; } return result; } }