MCPcopy
hub / github.com/codeaashu/claude-code / dequeue

Function dequeue

src/utils/messageQueueManager.ts:167–193  ·  view source on GitHub ↗
(
  filter?: (cmd: QueuedCommand) => boolean,
)

Source from the content-addressed store, hash-verified

165 * the existing while-loop patterns.
166 */
167export function dequeue(
168 filter?: (cmd: QueuedCommand) => boolean,
169): QueuedCommand | undefined {
170 if (commandQueue.length === 0) {
171 return undefined
172 }
173
174 // Find the first command with the highest priority (respecting filter)
175 let bestIdx = -1
176 let bestPriority = Infinity
177 for (let i = 0; i < commandQueue.length; i++) {
178 const cmd = commandQueue[i]!
179 if (filter && !filter(cmd)) continue
180 const priority = PRIORITY_ORDER[cmd.priority ?? 'next']
181 if (priority < bestPriority) {
182 bestIdx = i
183 bestPriority = priority
184 }
185 }
186
187 if (bestIdx === -1) return undefined
188
189 const [dequeued] = commandQueue.splice(bestIdx, 1)
190 notifySubscribers()
191 logOperation('dequeue')
192 return dequeued
193}
194
195/**
196 * Remove and return all commands from the queue.

Callers 3

processQueueIfReadyFunction · 0.85
drainCommandQueueFunction · 0.85

Calls 3

notifySubscribersFunction · 0.85
logOperationFunction · 0.85
spliceMethod · 0.80

Tested by

no test coverage detected