* Die IR fuer ein Symbol: aus dem Cache, aus einer laufenden Anfrage, oder * aus einer neuen.
(symbol: SymbolRef)
| 113 | * aus einer neuen. |
| 114 | */ |
| 115 | async load(symbol: SymbolRef): Promise<IrEntry> { |
| 116 | const key = irCacheKey(symbol); |
| 117 | if (key === undefined) { |
| 118 | // Kein Schluessel heisst kein Cache und keine Zusammenlegung, aber |
| 119 | // sehr wohl eine Antwort: ein Symbol ohne qualifizierten Namen ist |
| 120 | // ungewoehnlich, nicht unbeantwortbar. |
| 121 | this.onFetch(); |
| 122 | return this.fetcher(symbol); |
| 123 | } |
| 124 | const cached = this.peek(symbol); |
| 125 | if (cached !== undefined) { |
| 126 | return cached; |
| 127 | } |
| 128 | const running = this.inFlight.get(key); |
| 129 | if (running !== undefined) { |
| 130 | return running; |
| 131 | } |
| 132 | this.onFetch(); |
| 133 | const pending = this.fetcher(symbol) |
| 134 | .then((entry) => { |
| 135 | this.remember(key, entry); |
| 136 | return entry; |
| 137 | }) |
| 138 | .finally(() => { |
| 139 | this.inFlight.delete(key); |
| 140 | }); |
| 141 | this.inFlight.set(key, pending); |
| 142 | return pending; |
| 143 | } |
| 144 | |
| 145 | private remember(key: string, entry: IrEntry): void { |
| 146 | this.entries.delete(key); |
no test coverage detected