Not sore, but it looks like the Transition function has a race condition. It calls CanTansition() before acquiring the mutex lock. I think this could lead to illegal state transitions.
Show HN: State Trooper – Tiny, no frills state machine for Go
21–30 of 63 posts
Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#22[flagged]
wahnfrieden: Why the iron oxide name? Besides the fact that it's a pun. Is the code written with it always bound to be rusty and old?
Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#23Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#24That being said, I appreciate the simplicity and it's a totally fine choice to leave out event based dispatch for less complex use cases!
One thing that has been mentioned here already: it's super helpful to have your library output a diagram file to visualize the FSM. This is a really great way to keep code and documentation in sync always.
Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#25Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#26Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#27Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#28Interesting. I wrote almost the same code for work a couple of weeks ago. Not sore, but it looks like the Transition function has a race condition. It calls CanTansition() before acquiring the mutex lock. I think this could lead to illegal state transitions.
Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#29Re: Show HN: State Trooper – Tiny, no frills state machine for Go
#30Nice job. In my own usage of state machine libraries over the years I have found that for complex use cases, it's definitely helpful to have event-based transition dispatching be part of the library. The great benefit of FSMs is that you can express in data a lot of aspects that you would normally express in code. Not knowing what event needs to happen to transition to one state vs another leaves out a lot of the ben…
Re the visualization, I think that would be cool. I might give that a shot.