Derek Wyatt
Posts: 69
Nickname: dwyatt
Registered: Oct, 2012
|
|
Re: FSM's onTransition, transform and using
|
Posted: Jul 20, 2015 5:31 AM
|
|
From what I can gather, you might be getting things a bit confused; the four different things you've mentioned have four very distinct and important differences.
when and onTransition are related, but distinct.
You use when to declare what the message handler should be when you're in that particular state. You can think of when as saying "When the FSM is in this state, the receive partial function should be what is declared here". But a very important point is that it is merely a receive handler, and does not imply that any event has taken, or ever will actually take place.
There is an event that does take place when you transition from one state to another (i.e. from one when to another when), which is fired by the FSM itself. To capture these events and operate on them, you use onTransition.
Now, you're correct by saying that you could run the same "on transition" code from a specific case in a when but you would have to do that in every case that transitions to that "important" state. That could get exceedingly ugly and prone to error.
using and transform are used to declare the data for the next state, although transform is a bit more intricate.
Again, you could cobble together something that might let you completely ignore onTransition, using and transform but your code would probably look horrendous. If you still wanted to avoid using those abstractions, and make your code understandable and not-so-prone to bugs, you'd probably end up writing those abstractions anyway :)
|
|