gregschlom
06/12/2017, 6:31 PMclass CounterActor {
fun start(): ActorJob<CounterMsg> {
return actor<CounterMsg>(CommonPool, block = receive)
}
val receive: suspend ActorScope<CounterMsg>.() -> Unit = {
var counter = 0 // actor state
for (msg in channel) { // iterate over incoming messages
when (msg) {
is IncCounter -> counter++
is GetCounter -> msg.response.send(counter)
}
}
}
}