MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / processQueueIfReady

Function processQueueIfReady

src/utils/queueProcessor.ts:58–93  ·  view source on GitHub ↗
({
  executeInput,
}: ProcessQueueParams)

Source from the content-addressed store, hash-verified

56 * @returns result with processed status
57 */
58export function processQueueIfReady({
59 executeInput,
60}: ProcessQueueParams): ProcessQueueResult {
61 // This processor runs on the REPL main thread between turns. Skip anything
62 // addressed to a subagent — an unfiltered peek() returning a subagent
63 // notification would set targetMode, dequeueAllMatching would find nothing
64 // matching that mode with agentId===undefined, and we'd return processed:
65 // false with the queue unchanged → the React effect never re-fires and any
66 // queued user prompt stalls permanently.
67 const isMainThread = (cmd: QueuedCommand) => cmd.agentId === undefined
68
69 const next = peek(isMainThread)
70 if (!next) {
71 return { processed: false }
72 }
73
74 // Slash commands and bash-mode commands are processed individually.
75 // Bash commands need per-command error isolation, exit codes, and progress UI.
76 if (isSlashCommand(next) || next.mode === 'bash') {
77 const cmd = dequeue(isMainThread)!
78 void executeInput([cmd])
79 return { processed: true }
80 }
81
82 // Drain all non-slash-command items with the same mode at once.
83 const targetMode = next.mode
84 const commands = dequeueAllMatching(
85 cmd => isMainThread(cmd) && !isSlashCommand(cmd) && cmd.mode === targetMode,
86 )
87 if (commands.length === 0) {
88 return { processed: false }
89 }
90
91 void executeInput(commands)
92 return { processed: true }
93}
94
95/**
96 * Checks if the queue has pending commands.

Callers 2

useQueueProcessorFunction · 0.85

Calls 5

dequeueFunction · 0.85
dequeueAllMatchingFunction · 0.85
isSlashCommandFunction · 0.70
isMainThreadFunction · 0.70
peekFunction · 0.50

Tested by

no test coverage detected