freeletics / FlowRedux

Kotlin Multiplatform Statemachine library with nice DSL based on Flow from Kotlin Coroutine's.

Home Page:https://freeletics.github.io/FlowRedux/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make FlowReduxStatemachine "cold" again

sockeqwe opened this issue · comments

At the beginning FlowRedux the FlowReduxStatemachine was a "cold flow" (meaning on every new state.collect() the statemachine started with the initial state again).

Starting in FlowRedux 0.6.0 we then have made FlowReduxStatemachine a "hot flow" and have started using StateFlow (hot means the same state machine state will be collected / shared by all collectors; so it doesn't start with the initial state for every new state.collect {} ; plus statemachine can run without any active Collector as long as the CoroutineScope where the state machine launched in is active).

We thought this could give us some advantages with Freeletic's DI setup and Jetpack Compose, however it turns out the drawback's are bigger than expected. Just a few pain points:

  • Cancelation of a shared flow (like FlowReduxStateMachine) is harder
  • Tests became more flaky because FlowReduxStateMachine starts working without active Collectors that have called state.collect {...}. That leads to some state transitions being missed in unit test because the collector used in the test was not subscribed yet.

Therefore we are going to revert this. We will move away from StateFlow and make FlowReduxStateMachine "cold" again .

This should also solve #205