uli
03/07/2023, 4:06 PMdelay(1000)
is not canceled in this code:
fun main() = runBlocking(Dispatchers.Default) {
val viewModelScope = CoroutineScope(Dispatchers.Default)
val appScope = CoroutineScope(Dispatchers.Default)
viewModelScope.launch() {
println("Coroutine launched in viewModelScope!")
withContext(appScope.coroutineContext) {
try {
println("Coroutine launched in appScope?")
delay(1000)
println("One second passed")
} catch (c: CancellationException) {
println("appScope canceled: c")
throw c
}
}
}
delay(100)
viewModelScope.cancel()
println("viewModelScope canceled")
delay(1500)
println("Done")
}