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

State machine design: transitioning before effect? #19

Open
ursusursus opened this issue Jul 8, 2019 · 1 comment
Open

State machine design: transitioning before effect? #19

ursusursus opened this issue Jul 8, 2019 · 1 comment

Comments

@ursusursus
Copy link

ursusursus commented Jul 8, 2019

Hi, I wanna bounce of you a design question, since im trying to rewrite "implicit" state machine to explicit one

Usually the code looks like this

fun foo() {
   if (currentState == Bar) {
    doSomething()
    currentState = Quax
   }
}

What I usually see is people having transition function, which according to input action changes state, but however it would do so before doSomething is ran, to me which is a problem
since currentState will be observable, and subscribers expect doSomething to have ran if state is Quax

Do I need some PRE + POST_state pairs or something? Seems weird for synchronous code

What would be your solution?

@ursusursus
Copy link
Author

Ok I have looked at the way you guys use it in Scarlet

https://github.com/Tinder/Scarlet/blob/5457f827884269a7e1a7c1c60d057d0ed5fa26b1/scarlet/src/main/java/com/tinder/scarlet/internal/connection/Connection.kt

So, you are baking the statemachine inside StateManager, which then you can run those sideffects before transitions, great

However, this messes up testing, as you can only test StateManager, and statemachine become implmentation details, which is maybe okay

But you lose ability to set initialState, unless you pass it in via StateManager ctor, which is bad, since youre leaking your implementation detail to call sites

So...I'd like your guidance on this please

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