uli
delay(1000)
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") }
A modern programming language that makes developers happier.