1 export class PromiseCache <A, R> {
2 private readonly running = new Map<string, Promise<R>>()
5 private readonly fn: (arg: A) => Promise<R>,
6 private readonly keyBuilder: (arg: A) => string
11 const key = this.keyBuilder(arg)
13 if (this.running.has(key)) return this.running.get(key)
15 const p = this.fn(arg)
17 this.running.set(key, p)
19 return p.finally(() => this.running.delete(key))