Only commit a highlight result if the promise is still the active one for that key. * Prevents a superseded or late-resolving promise from overwriting a newer entry.
( cacheKey: string, promise: Promise<HighlightedDiffCode>, result: HighlightedDiffCode, )
| 86 | /** Only commit a highlight result if the promise is still the active one for that key. |
| 87 | * Prevents a superseded or late-resolving promise from overwriting a newer entry. */ |
| 88 | function commitHighlightResult( |
| 89 | cacheKey: string, |
| 90 | promise: Promise<HighlightedDiffCode>, |
| 91 | result: HighlightedDiffCode, |
| 92 | ) { |
| 93 | if (SHARED_HIGHLIGHT_PROMISES.get(cacheKey) !== promise) { |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | SHARED_HIGHLIGHT_PROMISES.delete(cacheKey); |
| 98 | SHARED_HIGHLIGHTED_DIFF_CACHE.set(cacheKey, result); |
| 99 | enforceCacheLimit(); |
| 100 | return true; |
| 101 | } |
| 102 | |
| 103 | /** Start one shared highlight request unless the cache or an in-flight promise already has it. */ |
| 104 | function ensureHighlightedDiffLoaded( |
no test coverage detected