dequeueAllMatching method

List<QueuedCommand> dequeueAllMatching(
  1. bool predicate(
    1. QueuedCommand
    )
)

Remove and return all commands matching a predicate.

Implementation

List<QueuedCommand> dequeueAllMatching(
  bool Function(QueuedCommand) predicate,
) {
  final matched = <QueuedCommand>[];
  final remaining = <QueuedCommand>[];

  for (final cmd in _commandQueue) {
    if (predicate(cmd)) {
      matched.add(cmd);
    } else {
      remaining.add(cmd);
    }
  }

  if (matched.isEmpty) return [];

  _commandQueue
    ..clear()
    ..addAll(remaining);
  _notifySubscribers();

  for (final _ in matched) {
    _logOperation(QueueOperation.dequeue);
  }

  return matched;
}