( filter?: (cmd: QueuedCommand) => boolean, )
| 217 | * Accepts an optional `filter` — only commands passing the predicate are considered. |
| 218 | */ |
| 219 | export function peek( |
| 220 | filter?: (cmd: QueuedCommand) => boolean, |
| 221 | ): QueuedCommand | undefined { |
| 222 | if (commandQueue.length === 0) { |
| 223 | return undefined |
| 224 | } |
| 225 | let bestIdx = -1 |
| 226 | let bestPriority = Infinity |
| 227 | for (let i = 0; i < commandQueue.length; i++) { |
| 228 | const cmd = commandQueue[i]! |
| 229 | if (filter && !filter(cmd)) continue |
| 230 | const priority = PRIORITY_ORDER[cmd.priority ?? 'next'] |
| 231 | if (priority < bestPriority) { |
| 232 | bestIdx = i |
| 233 | bestPriority = priority |
| 234 | } |
| 235 | } |
| 236 | if (bestIdx === -1) return undefined |
| 237 | return commandQueue[bestIdx] |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Remove and return all commands matching a predicate, preserving priority order. |
nothing calls this directly
no outgoing calls
no test coverage detected