In this example <https://github.com/Kotlin/kotlinx...
# coroutines
e
n
runBlocking
sets up a single threaded dispatcher running inside
runBlocking
on the callers thread.
val child = launch {
sets up the child coroutine but the child coroutine doesn't actually run.
yield
gives up the thread so that child coroutine can actually start. Without the first
yield
, the child coroutine wouldn't ever have a chance to run before
child.cancel()
was called. "Child is cancelled" would never be printed because lambda would never run at all due to it being cancelled before it even started. The second
yield
appears to be pointless since
join
gives up the thread until the child coroutine has finished.
mind blown 1
🙏 1