Can someone explain me what's happening here? 🧵 Thank you!
Karan Sharma
02/21/2024, 5:06 AM
Scenario 1 - When the exception happens in the first coroutine i.e Job1, does it also cancel the scope ?
The
join
will make sure that execution is sequential, therefore, understood that job2 coroutine should be executed after job1 completes. but it does not even launch a coroutine
Karan Sharma
02/21/2024, 5:08 AM
Scenario 2 - In this scenario, if I remove the join and make this parallel execution., the exception is not printed at all. why is that?
p
Patrick Steiger
02/21/2024, 5:14 AM
1 - A failure of the child cancels the parent scope (if not supervisor), yes. So this scope can’t be used anymore to launch new coroutines — it’s cancelled.
2 - Probably
main
finishes before throwing the exception, since it’s not under structured concurrency (
myScope
is not a child of the `runBlocking`scope).
👍 1
k
Karan Sharma
02/21/2024, 5:17 AM
1. yes that makes sense! thanks
Karan Sharma
02/21/2024, 5:19 AM
2. hmmm, yea looks like main finishes, before the coroutine has completed.