CLOVIS
02/22/2021, 3:53 PMwithContext(<http://Dispatchers.IO|Dispatchers.IO>) {
foo()
}
is conceptually equivalent as this one:
launch(<http://Dispatchers.IO|Dispatchers.IO>) {
foo()
}.join()
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?louiscad
02/22/2021, 3:55 PMThrowable
propagate up the scopes until caught, while the former will just throw from its call site.CLOVIS
02/22/2021, 4:24 PMStylianos Gakis
02/22/2021, 7:37 PMlaunch() { // }
as well. I don't really understand the exact differences there.louiscad
02/22/2021, 7:39 PMtry
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.Stylianos Gakis
02/22/2021, 7:53 PMlouiscad
02/22/2021, 9:51 PMCancellationException
that is uncaught in that launch { … }
call.