Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
fun main() {
lateinit var a: Deferred<Nothing>
lateinit var b: Deferred<Unit>
runBlocking { // Parent scope for both calls. When a fails, both coroutines get cancelled.
a = async { throw RuntimeException() }
b = async { delay(2000).also { println("I leaked!") } } // Will be printed!
}
println(a)
println(b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment