https://kotlinlang.org logo
#coroutines
Title
# coroutines
t

tseisel

01/29/2019, 9:03 PM
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

Allan Wang

01/29/2019, 9:05 PM
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

pakoito

01/29/2019, 11:05 PM
@tseisel the best documentation you’ll find is in other languages. I’d suggest looking into what exists for akka-actors for example.
d

Dico

01/30/2019, 3:30 AM
Akka does not use coroutines, i.e you have to write callbacks. That makes the code style very different (and more difficult).
a

Alexjok

01/30/2019, 6:37 AM
You can try read this Roman article https://medium.com/@elizarov/deadlocks-in-non-hierarchical-csp-e5910d137cc . It contains examples from the conference.
p

pakoito

01/30/2019, 11:03 AM
@Dico it was more about the architecture and patterns than the syntactic sugar.
d

Dico

01/30/2019, 11:22 AM
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.
5 Views