Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to model fsm where actions drive state? #172

Open
ursusursus opened this issue Nov 11, 2018 · 0 comments
Open

How to model fsm where actions drive state? #172

ursusursus opened this issue Nov 11, 2018 · 0 comments

Comments

@ursusursus
Copy link

ursusursus commented Nov 11, 2018

Hi, my question is not necessarily about this great library, but possibly a nudge in correct design decision

My usecase is audio calls. I am wrapping access to a very stateful api with a fsm. Api calls are asynchronous.

However, whats not so common in examples is that, if I were to input a transition to "makeCall" in state "idle", which is a valid transition, id output effect of onMakeCall, which would now actually call the api's makeCall, which ultimately drives the call state inside of the library api

In theory its all good, but this ping pong of throwing input in, getting effect out, making the actual method call, throwing another input from callback .. for every single action in the api feels weird.

Also, unluckily enough each api calls can synchronously return / throw error.

So basically I need Idle -> makeCall -> MakeCallPending -> api.makeCall, if not success then -> makeCallFailed -> Idle else from callback -> makeCallSucceeded -> Calling

regardless of library, should this be part of public api? Isnt nesting whole thing cleaner?

When state is Idle 
  When action is makeCall
    state = MakeCallPending
    val error = api.makeCall { 
       onCompleted {
          state = Calling
       }
    }
    if (error)
      state = Idle
    }

This would decrease the number of action objects, which are basically internal boilerplate

Thoughts? Thanks a lot in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant