Code Monkey home page Code Monkey logo

Comments (5)

ferllings avatar ferllings commented on August 27, 2024

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.

maxekman avatar maxekman commented on August 27, 2024

Can you provide a short code example?

from fsm.

ferllings avatar ferllings commented on August 27, 2024

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.

ferllings avatar ferllings commented on August 27, 2024

Hello,

Any idea?

I'm thinking of 2 modifications:

  1. Have an extra handler AFTER the state has been set and unlocked, so we can trigger new events from there

  2. have a queue of events? so when an async event arrives it doesn't end up on the mutex.

from fsm.

andersfylling avatar andersfylling commented on August 27, 2024

Any update on this?

from fsm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.