https://kotlinlang.org logo
#coroutines
Title
# coroutines
n

nerses

09/27/2018, 2:51 PM
hi, i have a question regarding new structured coroutines. In here it says https://github.com/Kotlin/kotlinx.coroutines/blob/master/docs/basics.md#scope-builder
The main difference between runBlocking and coroutineScope is that the latter does not block the current thread while waiting for all children to complete.
But when i run the example there the nested launch inside
coroutineScope
blocks the execution of the
runblocking
scope and the last
println("Coroutine scope is over")
is always printed the last. Am i getting it wrong? Or there is a mistake in the docs
k

kingsley

09/27/2018, 2:55 PM
coroutineScope
exits only after all the scoped coroutines have completed. However, it doesn’t block any thread. Once execution is suspended in the
coroutineScope
block, the thread is free to do some other work until the block is resumed again continuing from where it left off
n

nerses

09/27/2018, 3:53 PM
ah ok, thanks @kingsley after rereading that blog post it makes sense now 🙂
👍 1
2 Views