mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[command] Make cancel safe to call from initialize (#2440)
Fixes #2388.
This commit is contained in:
@@ -140,15 +140,16 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
* @param requirements The command requirements
|
||||
*/
|
||||
private void initCommand(Command command, boolean interruptible, Set<Subsystem> requirements) {
|
||||
command.initialize();
|
||||
CommandState scheduledCommand = new CommandState(interruptible);
|
||||
m_scheduledCommands.put(command, scheduledCommand);
|
||||
for (Consumer<Command> action : m_initActions) {
|
||||
action.accept(command);
|
||||
}
|
||||
command.initialize();
|
||||
for (Subsystem requirement : requirements) {
|
||||
m_requirements.put(requirement, command);
|
||||
}
|
||||
for (Consumer<Command> action : m_initActions) {
|
||||
action.accept(command);
|
||||
}
|
||||
|
||||
m_watchdog.addEpoch(command.getName() + ".initialize()");
|
||||
}
|
||||
|
||||
@@ -381,9 +382,11 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels commands. The scheduler will only call the interrupted method of a canceled command,
|
||||
* not the end method (though the interrupted method may itself call the end method). Commands
|
||||
* will be canceled even if they are not scheduled as interruptible.
|
||||
* Cancels commands. The scheduler will only call {@link Command#end(boolean)} method
|
||||
* of the canceled command with {@code true},
|
||||
* indicating they were canceled (as opposed to finishing normally).
|
||||
*
|
||||
* <p>Commands will be canceled even if they are not scheduled as interruptible.
|
||||
*
|
||||
* @param commands the commands to cancel
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user