( predicate: (cmd: QueuedCommand) => boolean, )
| 242 | * Non-matching commands stay in the queue. |
| 243 | */ |
| 244 | export function dequeueAllMatching( |
| 245 | predicate: (cmd: QueuedCommand) => boolean, |
| 246 | ): QueuedCommand[] { |
| 247 | const matched: QueuedCommand[] = [] |
| 248 | const remaining: QueuedCommand[] = [] |
| 249 | for (const cmd of commandQueue) { |
| 250 | if (predicate(cmd)) { |
| 251 | matched.push(cmd) |
| 252 | } else { |
| 253 | remaining.push(cmd) |
| 254 | } |
| 255 | } |
| 256 | if (matched.length === 0) { |
| 257 | return [] |
| 258 | } |
| 259 | commandQueue.length = 0 |
| 260 | commandQueue.push(...remaining) |
| 261 | notifySubscribers() |
| 262 | for (const _cmd of matched) { |
| 263 | logOperation('dequeue') |
| 264 | } |
| 265 | return matched |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Remove specific commands from the queue by reference identity. |
no test coverage detected