Comments (5)
Any idea?
For now I'm lunching my event callbacks calls in a goroutine.
It seems to do the trick, but can fail in race condition.
from fsm.
Can you provide a short code example?
from fsm.
I'm trying to convert a nodejs lib protocol based on machina.
I believe my problem comes from the fact that many of my events are async.
Here is an eluded of the code:
// Launch a message listener
go messagesListener()
// Starts connection protocol
FSM.Event("requestConnection")
fsm.NewFSM(
"uninitialized",
fsm.Events{
{Name: "requestConnection", Src: []string{"uninitialized"}, Dst: "connecting"},
{Name: "confirmConnection", Src: []string{"connecting"}, Dst: "connected"},
{Name: "deniedConnection", Src: []string{"connecting"}, Dst: "uninitialized"},
{Name: "inbound_CONNECT_RESPONSE", Src: []string{"connecting"}, Dst: "connecting"},
...
},
fsm.Callbacks{
"enter_connecting": func(e *fsm.Event) {
...
// try to connect 3 times
// After 3 times with no response go back on "uninitialized"
FSM.Event("deniedConnection")
...
},
"inbound_CONNECT_RESPONSE": func(e *fsm.Event) {
...
// If the response code is ok we move to "connected"
FSM.Event("confirmConnection")
// If the target is busy we wait for 1 min before retrying
}
}
)
func messagesListener() {
// if connection response received
FSM.Event("inbound_CONNECT_RESPONSE")
}
from fsm.
Hello,
Any idea?
I'm thinking of 2 modifications:
-
Have an extra handler AFTER the state has been set and unlocked, so we can trigger new events from there
-
have a queue of events? so when an async event arrives it doesn't end up on the mutex.
from fsm.
Any update on this?
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.