I’m doing this right now, not sure if that’s the b...
# coroutines
g
I’m doing this right now, not sure if that’s the best way:
Copy code
class 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)
            }
        }
    }
}