February 2018
Intermediate to advanced
350 pages
7h 35m
English
Coroutines always run in a context. All coroutine builders have context specified by default, and that context is available through the value coroutineContext, inside the coroutine body:
import kotlinx.coroutines.experimental.*fun main(args: Array<String>) = runBlocking { println("run blocking coroutineContext = $coroutineContext") println("coroutineContext[Job] = ${coroutineContext[Job]}") println(Thread.currentThread().name) println("-----") val jobs = listOf( launch { println("launch coroutineContext = $coroutineContext") println("coroutineContext[Job] = ${coroutineContext[Job]}") println(Thread.currentThread().name) println("-----") }, async { println("async coroutineContext = $coroutineContext") println("coroutineContext[Job] ...
Read now
Unlock full access