July 2018
Intermediate to advanced
266 pages
7h 11m
English
In many cases, we have coroutines that are long-lasting, for example, if we have an actor or a producer and we want to specify which name should be used for them when the VM flag is passed. We can pass a parameter to the coroutine builders to specify the name that we want, and then we can easily find the entries in the log for that coroutine. Let's do a simple implementation of this:
val pool = newFixedThreadPoolContext(3, "myPool")val ctx = newSingleThreadContext("ctx")withContext(pool + CoroutineName("main")) { println("Running in ${threadName()}") withContext(ctx + CoroutineName("inner")) { println("Switching to ${threadName()}") }}
This example uses CoroutineName to give a specific name to the coroutine. Because ...
Read now
Unlock full access