There is a concept of actor
in Kotlin coroutines library:
fun CoroutineScope.counterActor() = actor<CounterMsg> {
var counter = 0 // actor state
for (msg in channel) { // iterate over incoming messages
when (msg) {
is IncCounter -> counter++
is GetCounter -> msg.response.complete(counter)
}
}
}
The documentation says that
A simple actor can be written as a function, but an actor with a complex state is better suited for a class.
What would be a good example of an actor defined as a class in Kotlin?