peek method

QueuedCommand? peek({
  1. bool filter(
    1. QueuedCommand
    )?,
})

Return the highest-priority command without removing it.

Implementation

QueuedCommand? peek({bool Function(QueuedCommand)? filter}) {
  if (_commandQueue.isEmpty) return null;

  int bestIdx = -1;
  int bestPriority = 999;

  for (int i = 0; i < _commandQueue.length; i++) {
    final cmd = _commandQueue[i];
    if (filter != null && !filter(cmd)) continue;
    final priority = cmd.priority.order;
    if (priority < bestPriority) {
      bestIdx = i;
      bestPriority = priority;
    }
  }

  if (bestIdx == -1) return null;
  return _commandQueue[bestIdx];
}