February 2018
Intermediate to advanced
350 pages
7h 35m
English
Now, let's rewrite our Hello World application with coroutines.
But, hey! What is a coroutine? Basically, a coroutine is a very light thread that runs a block of code and has a similar life cycle, but can complete with a return value or an exception. Technically, a coroutine is an instance of a suspendable computation, a computation that may suspend. Coroutines aren't bound to a particular thread and can suspend in one Thread and resume execution in a different one:
import kotlinx.coroutines.experimental.delayimport kotlinx.coroutines.experimental.launchimport kotlinx.coroutines.experimental.runBlockingfun main(args: Array<String>) = runBlocking { launch { delay(1000) println("World") } print("Hello ") delay(2000
Read now
Unlock full access