Kotlin Coroutines с SupervisorJob отменяет дочерние элементыAndroid

Форум для тех, кто программирует под 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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»