Open harendra-kumar opened 5 years ago
Instead of using fork/join typeclasses we can have a Monoid
instance on the state of the monad and combine the states of the concurrent actions on completion.
Currently the MonadState
instance for concurrent streams is broken. We should either fix this issue or remove that instance. Marking this issue as a bug because of that.
MonadState is broken for concurrent streams in Streamly.Prelude but we are deprecating that module in 0.9.0 and now we have explicit concurrency via Data.Stream.Concurrent, so we are leaving MonadState for old streams as is.
To support concurrent modification of shared state we need a concurrent StateT. A concurrent StateT would fork the shared state to multiple concurrent threads and then join the modified state back to create a common modified shared state. We can have
fork
andjoin
typeclasses to facilitate the forking an combining of state.In addition to StateT, ExceptT is another candidate for fork and join of state.