Hey, wondering if anyone has best practices tips /...
# functional
n
Hey, wondering if anyone has best practices tips / examples for implementing a "Tool" (i.e. asynchronous user workflow with a specific start / end, as opposed to something with an open-ended lifecycle like a view) in a MVU/Elm style using Kotlin coroutines. We currently have a sealed class "action" interface for representing actions the user can perform to interact with the tool, and a reducer function
(State, Action) -> State
, but my question was more about how to actually action this reducer to do stuff with the UI. Currently we are taking in a Flow of Actions, an initial state, and updating that state (as a StateFlow) by launching a collect block on the action flow to update the state. The body of the collect statement on the flow is synchronized with a mutex so actions should (I was hoping anyway) get executed in order sequentially. In practice, this seems to work. However, I've noticed in tests this sometimes fails, which makes me wonder if my setup of this is actually optimal. I was thinking maybe a channel of user actions might be more robust, but open to ideas!