( predicate: (cmd: QueuedCommand) => boolean, )
| 296 | * Returns the removed commands. |
| 297 | */ |
| 298 | export function removeByFilter( |
| 299 | predicate: (cmd: QueuedCommand) => boolean, |
| 300 | ): QueuedCommand[] { |
| 301 | const removed: QueuedCommand[] = [] |
| 302 | for (let i = commandQueue.length - 1; i >= 0; i--) { |
| 303 | if (predicate(commandQueue[i]!)) { |
| 304 | removed.unshift(commandQueue.splice(i, 1)[0]!) |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | if (removed.length > 0) { |
| 309 | notifySubscribers() |
| 310 | for (const _cmd of removed) { |
| 311 | logOperation('remove') |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | return removed |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * Clear all commands from the queue. |
no test coverage detected