When using the debugger in IntelliJ IDEA or Android Studio, we can take advantage of the -Dkotlinx.coroutines.debug flag as well. It can facilitate the general debugging of the app, and it can be used for setting breakpoints that will happen only for a given coroutine. Let's work with the following piece of code:
val pool = newFixedThreadPoolContext(3, "myPool")
val ctx = newSingleThreadContext("ctx")
for (i in 0..5) {
async(pool + CoroutineName("main")) {
val year = Calendar.getInstance().get(Calendar.YEAR)
withContext(ctx + CoroutineName("inner")) {
println(year)
}
}.await()
}