Skip to content

Commit

Permalink
[commands] Improve isScheduled to be more performant when checking …
Browse files Browse the repository at this point in the history
…a single command (#7096)
  • Loading branch information
oh-yes-0-fps authored Sep 23, 2024
1 parent 22f086a commit 180349b
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,28 @@ public void cancelAll() {
* scheduled by the scheduler; it will not work on commands inside compositions, as the scheduler
* does not see them.
*
* @param commands the command to query
* @return whether the command is currently scheduled
* @param commands multiple commands to check
* @return whether all of the commands are currently scheduled
*/
public boolean isScheduled(Command... commands) {
return m_scheduledCommands.containsAll(Set.of(commands));
for (var cmd : commands) {
if (!isScheduled(cmd)) {
return false;
}
}
return true;
}

/**
* Whether the given commands are running. Note that this only works on commands that are directly
* scheduled by the scheduler; it will not work on commands inside compositions, as the scheduler
* does not see them.
*
* @param command a single command to check
* @return whether all of the commands are currently scheduled
*/
public boolean isScheduled(Command command) {
return m_scheduledCommands.contains(command);
}

/**
Expand Down

0 comments on commit 180349b

Please sign in to comment.