("자체는 영향을받지 않습니다이 작업의 상태를.") 내가 가지고 그러나 경우cancelChildren은 Kotlin Coroutines에서 어떻게 작동해야합니까? 코 루틴의 아이들을 취소하지만 영향을받지 부모 떠나야한다 문서의 cancelChildren에 따르면
val outer = launch {
try {
launch (coroutineContext) {
try {
// work here
} catch (ex: Exception) {
println("In inner catch")
} finally {
println("In inner finally")
}
}
delay(5000) // so the outer job is running when I cancel it
} catch (ex: CancellationException) {
println("In outer catch")
} finally {
println("In outer finally")
}
}
delay(100) // give it a chance to run
outer.cancelChildren()
그럼 내가 볼처럼 코드
다음In inner catch
In inner finally
In outer catch
In outer finally
'외부'작업이 취소되는 이유는 무엇입니까?
이 outer.cancelChildren()
에 의해 영향을 받는다 따라서 외부 코 루틴에 내가 outer.cancel 호출하면 내가 할 (하지만 기대) 동일한 행동
감사합니다. 일시 중단 함수 (지연, 조인 ...)는 내가 알지 못했던 CancellationException을 전파합니다. 이것은 '부모'가 '어린이'가 취소되었음을 알고 있어야하므로 의미가 있습니다. –
예, 정확하게는 :-) – s1m0nw1