I have watched the "Kotlin Coroutines in Practice"...
# coroutines
t
I have watched the "Kotlin Coroutines in Practice" talk by Roman Elizarov and learned about the Actor pattern to confine shared mutable state to a coroutine. In this talk, actors are defined using a function whose parameters are ReceiveChannel (for inputs) or SendChannel (for outputs). Since those actors are defined as functions, how does they relate to classes ? Does anyone has concrete examples of how to structure a program with coroutines-based actors ?
a
If you look at the source for actors, they basically create a channel, allow you to define some behaviour on item receivers, then close them when the job closes. So class wise it’s basically just channels with an added on close handler
p
@tseisel the best documentation you’ll find is in other languages. I’d suggest looking into what exists for akka-actors for example.
d
Akka does not use coroutines, i.e you have to write callbacks. That makes the code style very different (and more difficult).
a
You can try read this Roman article https://medium.com/@elizarov/deadlocks-in-non-hierarchical-csp-e5910d137cc . It contains examples from the conference.
p
@Dico it was more about the architecture and patterns than the syntactic sugar.
d
I mean that the architecture might have evolved differently, impacted by the significant difference in syntactic sugar. But you are right, looking at akka might provide helpful insight.