fgmacedo / python-statemachine

Python Finite State Machines made easy.
MIT License
854 stars 84 forks source link

feature request: return to previous state #439

Open bernarde01 opened 3 months ago

bernarde01 commented 3 months ago

Thanks for an awesome tool!

I have a state machine that can go to an "ask if exit" state from every state. It would be great if I could define this ask_if_exit as a single state, and then enable this state to transition back to the previous state if the user does not want to exit.

This means that this transition will need to be dynamically defined. I have tried to do this using the library, but no luck. I forked the repo to see if I can implement this, but I don't see how this would be possible.

fgmacedo commented 6 days ago

Hi @bernarde01, how are you? Thanks for your suggestion! I really liked it and believe it would be a great addition to the library.

I’m still exploring how to implement this. A related concept in the literature is history pseudo-states, which are defined in the SCXML standard: https://www.w3.org/TR/scxml/#history.

If we can incorporate both history and compound states, this could become a viable solution.

I have an ongoing effort to add support for compound states in this PR: https://github.com/fgmacedo/python-statemachine/pull/329. I’m working on refining this into a non-breaking API, but it’s a significant and complex task.