Comments (11)
I still think this should be looked at. The comment from @ppwfx isn't correct or I'm misunderstanding what he's saying. While the implementation of this library is based on a determinstic fsm, a determinstic fsm allows for multiple transitions out of a state, and even back into the same state, for different input. We're not talking about allowing multiple transition from a state with the same input. That would make it a NFA. What this issue is about does not fall outside of a DFA.
So in my case, we have an fsm where you have to upload at least one document, but you may need to upload multiple
{Name: "upload", Src: []string{"need-upload", "uploaded"}, Dst: "uploaded"}, {Name: "start", Src: []string{"uploaded"}, Dst: "started"},
You transition to uploaded
once you have uploaded one piece, but then you should be able to upload multiple pieces of proof. This is why a self transition makes sense. You should still trigger the before and after functions, as the transition is still occurring.
from fsm.
I've just been bitten by this issue. Any progress on this?
I'd also suggest that leave and enter state actually do fire, as the state machine is transitioning out of the state and back into the state - its more that the transition has occurred and resulted in the same state, rather than the event itself has fired.
Example, think of a simple game with two players. You may want the game to transition between player turns:
{Name: "PlayerEndsTurn", Src: []string{"player_turn"}, Dst: "player_turn"},
{Name: "AllPlayerPiecesHaveBeenMoved", Src: []string{"player_turn"}, Dst: "player_turn"},
and have a callback for enter_ player_turn that setups up the state for each player on their turn. It's not the event that is important here, as there may be other events that trigger the transition to a new player_turn (such as the last possible piece movable by the player being moved).
from fsm.
I think the transition should happen, but the leave state and then enter state may not happen since it's just a self transition.
The transition needs to be a first class citizen. Currently beforeEvent and afterEvent hides the actual transition logic that needs to occur.
Adding one more callback called "doEvent" might be needed.
from fsm.
If you expect a self transition just check for the error. If you want to treat it as an error or not is up to you.
from fsm.
Or did you want to do something more with a self transition? Callbacks etc.
from fsm.
a self transition is completely valid in state machines, FSM should really support it and not consider it an error. Perhaps it's ok to not leave the state and then renter the same state, but the transition should still be valid and not be considered and error.
from fsm.
Yes, an error could be misleading in this case, I definitely see your point. Let's discuss this further. What changes do you suggest? Does the fact that no transition happened need to be fed back into one of the callbacks or something similar?
from fsm.
This is a deterministic state machine implementation. That's why every state can only have one dst.
There is a really simple solution tho, just add a second state machine that is created when a state is reached that has state on its own.
from fsm.
I'll close this, referring to the last comment.
from fsm.
any comments/updates on this? i think @pajacobs17 is right. currently we need to implement all self transitions ourselves (by handling the transition error) since we the lib is not supporting it which is a bit annoying.
Compare: http://www.phon.ox.ac.uk/jcoleman/new_SLP/Lecture_1/FSMs.html chapter "self loops"
from fsm.
Hi Team, The state machine is not supporting transition from and to if its same state. There is a business requirement to allow the state transition and trigger some events in case of the from and to state is same. Any recommendation here would be appreciated
from fsm.
Related Issues (20)
- How to cancel a transition in callback?
- Deadlock calling `Event` in after-event callback when current state == dst
- Changing `Event.Dst` in before-event callback do not changing dst of transition HOT 1
- Why does the following test produce a data race? HOT 2
- New Release ? HOT 2
- Return errors as wrapped errors instead of a custom struct HOT 1
- Testing FSM objects: reflect.DeepEqual fails when FSM attribute is set on an object HOT 1
- fix typo HOT 1
- Can FSM.Transaction() accept a parameter to cancel the asynchronous transaction? HOT 2
- Any plan for supporting UML state machine? HOT 1
- callback error HOT 4
- Is this abandoned? HOT 2
- when I use SetState in a callback in a `before_<event>` => deadlock HOT 4
- fsm.Event(ctx, ...) not work properly with context.WithTimeout() HOT 2
- Why fsm code not update to the latest version HOT 3
- Using enum instead strings
- Should cancelFunc be public? HOT 1
- Separate module path for the v1 releases
- Allow "No Transition" HOT 1
- Callbacks for complex FSM HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fsm.