// 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 call(): Promise { if (!this.promise) { let result: T | null = null; let promise = new Promise(async (resolve) => { resolve(await this.func()); }); // This if statement could trigger if func is not async // typescript is missing some fun stuff going on here :) if (result) { return result; } else { this.promise = promise; } } return await this.promise; } }