Kotlin Coroutines с SupervisorJob отменяет дочерние элементы ⇐ Android
Kotlin Coroutines с SupervisorJob отменяет дочерние элементы
Why does scope with SupervisorJob cancel child launches? I don't need to know how to fix it, I want to understand the logic. After all, SupervisorJob should not cancel child coroutines
suspend fun main() { val scope = CoroutineScope(SupervisorJob()) scope.launch { launch { f1() } launch { f2() } launch { error() } } } suspend fun f1() { delay(300) println("f1") } suspend fun f2() { delay(300) println("f2") } Result: Nothing. And why is the error not thrown out?
UPD. If write it so it will be ok. But why?
scope.launch { .. } scope.launch { .. } scope.launch { .. }
Источник: https://stackoverflow.com/questions/781 ... cel-childs
Why does scope with SupervisorJob cancel child launches? I don't need to know how to fix it, I want to understand the logic. After all, SupervisorJob should not cancel child coroutines
suspend fun main() { val scope = CoroutineScope(SupervisorJob()) scope.launch { launch { f1() } launch { f2() } launch { error() } } } suspend fun f1() { delay(300) println("f1") } suspend fun f2() { delay(300) println("f2") } Result: Nothing. And why is the error not thrown out?
UPD. If write it so it will be ok. But why?
scope.launch { .. } scope.launch { .. } scope.launch { .. }
Источник: https://stackoverflow.com/questions/781 ... cel-childs
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение