July 2018
Intermediate to advanced
266 pages
7h 11m
English
Like we did to solve the counter example, you can pass a CoroutineContext when building an actor. The suspending lambda of the actor will be executed in the given context. For example, you can create an actor that processes its messages in a pool of threads:
val dispatcher = newFixedThreadPoolContext(3, "pool")val actor = actor<String>(dispatcher) { for (msg in channel) { println("Running in ${Thread.currentThread().name}") }}for (i in 1..10) { actor.send("a")}
The suspending lambda will be executed accordingly:

Read now
Unlock full access