eneim
02/23/2022, 1:02 AMNick Allen
02/23/2022, 1:39 AMrunBlocking 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.