July 2018
Intermediate to advanced
266 pages
7h 11m
English
So far, we have seen how to create coroutines using async() and launch(), but in both cases we were using the default dispatcher. Consider the following code:
fun main(args: Array<String>) = runBlocking { val task = launch { printCurrentThread() } task.join()}
Here, printCurrentThread(), as its name suggests, will just print the name of the current thread to the standard output:
fun printCurrentThread() { println("Running in thread [${Thread.currentThread().name}]")}
By running this code, we see that by default the coroutine will run in DefaultDispatcher, which as the time of writing is the same dispatcher as CommonPool – but be aware that this could change in the future.
If we update ...
Read now
Unlock full access