Normal commands have a whenCanceled method in the NeedsNameBuilderStage, but StateMachines don't have one as they're not normal staged commands. It would be beneficial to add one as StateMachines can still be cancelled like normal commands. Currently the alternative is to wrap the StateMachine in a staged command and add a whenCanceled condition there, but that adds boilerplate and creates an extra command that shouldn't really be needed.
There could be a whenCanceled(Runnable) method that stores a callback, then the StateMachine overrides the onCancel() method to run that callback. It would look something like this (Java):
private Runnable m_onCancel = () -> {};
public void whenCanceled(Runnable onCancel) {
m_onCancel = onCancel;
}
@Override
public void onCancel() {
m_onCancel.run();
}
It may also be a good idea to run the current state's exit sequence at the top of the onCancel method to help with cleanup. The main difference between a State's onExit and the whenCanceled is that the latter would be global and run regardless of which state is running.
Normal commands have a whenCanceled method in the NeedsNameBuilderStage, but StateMachines don't have one as they're not normal staged commands. It would be beneficial to add one as StateMachines can still be cancelled like normal commands. Currently the alternative is to wrap the StateMachine in a staged command and add a whenCanceled condition there, but that adds boilerplate and creates an extra command that shouldn't really be needed.
There could be a whenCanceled(Runnable) method that stores a callback, then the StateMachine overrides the onCancel() method to run that callback. It would look something like this (Java):
It may also be a good idea to run the current state's exit sequence at the top of the onCancel method to help with cleanup. The main difference between a State's onExit and the whenCanceled is that the latter would be global and run regardless of which state is running.