MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / useQueueProcessor

Function useQueueProcessor

source code/hooks/useQueueProcessor.ts:30–70  ·  view source on GitHub ↗
({
  executeQueuedInput,
  hasActiveLocalJsxUI,
  queryGuard,
}: UseQueueProcessorParams)

Source from the content-addressed store, hash-verified

28 * - No active local JSX UI blocking input
29 */
30export function useQueueProcessor({
31 executeQueuedInput,
32 hasActiveLocalJsxUI,
33 queryGuard,
34}: UseQueueProcessorParams): void {
35 // Subscribe to the query guard. Re-renders when a query starts or ends
36 // (or when reserve/cancelReservation transitions dispatching state).
37 const isQueryActive = useSyncExternalStore(
38 queryGuard.subscribe,
39 queryGuard.getSnapshot,
40 )
41
42 // Subscribe to the unified command queue via useSyncExternalStore.
43 // This guarantees re-render when the store changes, bypassing
44 // React context propagation delays that cause missed notifications in Ink.
45 const queueSnapshot = useSyncExternalStore(
46 subscribeToCommandQueue,
47 getCommandQueueSnapshot,
48 )
49
50 useEffect(() => {
51 if (isQueryActive) return
52 if (hasActiveLocalJsxUI) return
53 if (queueSnapshot.length === 0) return
54
55 // Reservation is now owned by handlePromptSubmit (inside executeUserInput's
56 // try block). The sync chain executeQueuedInput → handlePromptSubmit →
57 // executeUserInput → queryGuard.reserve() runs before the first real await,
58 // so by the time React re-runs this effect (due to the dequeue-triggered
59 // snapshot change), isQueryActive is already true (dispatching) and the
60 // guard above returns early. handlePromptSubmit's finally releases the
61 // reservation via cancelReservation() (no-op if onQuery already ran end()).
62 processQueueIfReady({ executeInput: executeQueuedInput })
63 }, [
64 queueSnapshot,
65 isQueryActive,
66 executeQueuedInput,
67 hasActiveLocalJsxUI,
68 queryGuard,
69 ])
70}

Callers 1

REPLFunction · 0.85

Calls 1

processQueueIfReadyFunction · 0.85

Tested by

no test coverage detected