MCPcopy Create free account
hub / github.com/modem-dev/hunk / commitHighlightResult

Function commitHighlightResult

src/ui/diff/useHighlightedDiff.ts:88–101  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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. */
88function 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. */
104function ensureHighlightedDiffLoaded(

Callers 1

Calls 1

enforceCacheLimitFunction · 0.85

Tested by

no test coverage detected