spand
11/28/2018, 8:19 AMJob()
as an explicit lifecycle as mentioned here: https://github.com/Kotlin/kotlinx.coroutines/blob/master/docs/coroutine-context-and-dispatchers.md#cancellation-via-explicit-job
Is installing a CoroutineExceptionHandler
the only way to handle exceptions in the lifecycle ?gildor
11/28/2018, 8:21 AMgildor
11/28/2018, 8:22 AMspand
11/28/2018, 8:24 AMprintln("Coroutine $i is done")
gildor
11/28/2018, 8:26 AMgildor
11/28/2018, 8:26 AMspand
11/28/2018, 8:27 AMjob
?spand
11/28/2018, 8:28 AMtry { job.join() } catch (e: Exception) { handleException }
gildor
11/28/2018, 8:29 AMspand
11/28/2018, 8:29 AMgildor
11/28/2018, 8:29 AMgildor
11/28/2018, 8:30 AMdeferred.await()
which throws exception, not join()
Structured concurrency changed this, it’s true, but just in terms, that you can try/catch/finally exception, but if child is crashed, parent will be also cancelled to avoid leaking of other coroutines. To use old behaviour you need SupervisorJob, in this case crash of child will not cancel parent and it’s your responsibility to manage running coroutines in case of errorspand
11/28/2018, 8:30 AMgildor
11/28/2018, 8:32 AMtry { job.join() }
use asinc/await instead of launch: try { deferred.await() }
Tolriq
11/28/2018, 10:59 AM