diff --git a/src/command.rs b/src/command.rs index c7d4cd4..75572b5 100644 --- a/src/command.rs +++ b/src/command.rs @@ -186,10 +186,19 @@ impl Command for GenericCommand { } fn reset(&mut self) { - self.context.status = CommandStatus::Stopped; + use self::CommandStatus::*; + self.context.status = match self.context.status { + Ended | Cancelled => Stopped, + other => other, + }; } + fn cancel(&mut self) { - self.context.status = CommandStatus::Cancelling; + use self::CommandStatus::*; + self.context.status = match self.context.status { + Running => Cancelling, + other => other, + }; } } @@ -333,6 +342,7 @@ impl CommandImp for CommandGroupConfig { let mut command = command.borrow_mut(); command.cancel(); command.execute(); + command.reset(); } } } @@ -408,7 +418,10 @@ impl CommandScheduler { self.running_commands.drain_filter(|command_run| { let mut command = command_run.command.borrow_mut(); match command.execute() { - Ended | Cancelled => true, + Ended | Cancelled => { + command.reset(); + true + }, Stopped | Running | Cancelling => false, } });