napperley
12/24/2017, 10:31 PMlouiscad
12/24/2017, 10:33 PMnapperley
12/24/2017, 10:47 PMlouiscad
12/25/2017, 12:23 AMrunBlocking { … }
, which only allows to keep the calling thread active while the coroutine inside it's lambda are run, but there's no suspending code inside, so as Ken Yee said, yes, your CPU usage will be high until the print statements are executed. Did you understand the purpose of coroutines?snrostov
12/25/2017, 12:23 AMdelay(100)
at the end of printMessage
runAsync
inside loopfun main(args: Array<String>) = runBlocking<Unit> {
val jobs = List(100_000) { // launch a lot of coroutines and list their jobs
launch {
delay(1000L)
print(".")
}
}
jobs.forEach { it.join() } // wait for all jobs to complete
}
napperley
12/26/2017, 9:53 PM