Hi Kirill Rozov thanks for the response, if your concern is about canceling the child coroutines so when child coroutine raises any exception than no need to worry it will cancel the parent coroutine which leads to cancelation of all child coroutines.
SupervisorJob is great to have when you do not want child to cancel the parent coroutine hence exception in one child coroutine will not effect the overall childrens of parent coroutines. Whenever you cancel the parent coroutine than only it will cancel all childrens.
val handler = CoroutineExceptionHandler { _, exception ->
println(“Caught $exception with suppressed ${exception.suppressed.contentToString()}”)
}
val job = GlobalScope.launch(handler) {
launch {
repeat(10) { i ->
println(“I’m sleeping $i …”)
if(i == 5) {
val num = i / 0
}
delay(500L)
}
repeat(10) { i ->
async {
println(“It’s in async”)
}
delay(100L)
}
}
}
delay(5300L) // delay a bit
println(“main: I’m tired of waiting!”)
//job.cancel() // cancels the job
job.join() // waits for job’s completion
println(“main: Now I can quit.”)