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

Function queueHighlightedWork

src/ui/diff/pierre.ts:596–618  ·  view source on GitHub ↗

Queue highlight rendering so startup work stays serialized without starving input/render timers.

(run: () => T)

Source from the content-addressed store, hash-verified

594
595/** Queue highlight rendering so startup work stays serialized without starving input/render timers. */
596function queueHighlightedWork<T>(run: () => T) {
597 const queued = queuedHighlightWork.then(
598 () =>
599 new Promise<T>((resolve, reject) => {
600 // Highlighting is CPU-heavy background work. Scheduling each serialized job as a timer,
601 // rather than a microtask, yields back to OpenTUI input and frame timers between files.
602 setTimeout(() => {
603 try {
604 resolve(run());
605 } catch (error) {
606 reject(error);
607 }
608 }, 0);
609 }),
610 );
611
612 queuedHighlightWork = queued.then(
613 () => undefined,
614 () => undefined,
615 );
616
617 return queued;
618}
619
620/** Normalize source text the same way expanded-row slicing does before highlighting. */
621function normalizeSourceText(text: string) {

Callers 2

loadHighlightedDiffFunction · 0.85

Calls 1

runFunction · 0.50

Tested by

no test coverage detected