ursus
11/17/2018, 5:39 PMwhen state == Activated
when action == MuteMic
state = ActivatedMuteMicPending
effect(Effect.DoMuteMic)
state = Activated
sealed class State {
object Activated,
object ActivatedMuteMicPending
}
im not sure if this is good designlouiscad
11/17/2018, 6:43 PMwhen
can't compile to begin withursus
11/17/2018, 7:20 PMTimmy
11/18/2018, 12:43 AMursus
11/18/2018, 1:33 AMTimmy
11/18/2018, 5:21 PMActivatedMuteMicPending
) would not reduce the complexity (all these combinations of action and state would still exist) and actually increase the complexity. You might be able to write an abstraction on these pending state transitions, if you have the same pattern multiple times.
The biggest takeaway from this example code for me however was the fact that it feels wrong to have asynchronous state transitions. They introduce so many gotchas (e.g. my example code has shared mutable access to state
).
A more asynchronous friendly approach would be to use actors (another topic that I'm not really that well versed in). Have a look at conflated channels to see if they can help you.ursus
11/19/2018, 3:24 AMTimmy
11/19/2018, 11:31 AMursus
11/19/2018, 3:17 PM