Hi. I need to create an actor that will own some m...
# coroutines
Hi. I need to create an actor that will own some mutable state and offer a request-response interface to manipulate it. What is the proper way to achieve that with coroutines and channels? Perhaps: - One single inbound channel that the clients use to send requests. - Each client creates its own reply channel, that is added to the request. - The actor coroutine sequentially fetch requests from the inbound channel, processes them, and sends the response to the reply channel referenced in the request. So, there will be a single request channel and one reply channel per client. Does this make sense? Is it possible to avoid having a reply channel per client?
This is not an answer but https://github.com/Kotlin/kotlinx.coroutines/issues/87 might point you in the right direction.
Thanks. In the meanwhile I've read https://kotlinlang.org/docs/reference/coroutines/shared-mutable-state-and-concurrency.html and there's an example using
to provide the mechanism for the replies.