Since the implementation is very different, I expect that for performance reasons it does something else, but as a developer should I use
withContext
as syntax sugar for
launch().join()
, or is there something else I need to know about?
l
louiscad
02/22/2021, 3:55 PM
@CLOVIS if the second one crashes, it will cancel the parent scope, and have the
Throwable
propagate up the scopes until caught, while the former will just throw from its call site.
c
CLOVIS
02/22/2021, 4:24 PM
Really good to know, thanks!
s
Stylianos Gakis
02/22/2021, 7:37 PM
Would the top one not also cancel the parent scope? If not, why not? That must also have started at some point with
launch() { // }
as well. I don't really understand the exact differences there.
l
louiscad
02/22/2021, 7:39 PM
@Stylianos Gakis If the top one is surrounded with a
try
catch
block, it'll not crash the scope, while for the second one, the scope will crash (cancelling any other childs, the siblings of the crashed coroutines) and propagate the exception anyway.
s
Stylianos Gakis
02/22/2021, 7:53 PM
Aha, so even if the bottom option is also surrounded with try catch on the call site, it will still crash since it's inside a different job (? or what would that be called?) it will crash and propagate up. Thanks for the clarification!
l
louiscad
02/22/2021, 9:51 PM
The second option launches a child job. By crash, I mean throwing something other than a