Last active
April 28, 2021 08:59
-
-
Save soudmaijer/20e890883283ca2e07e1af6923771c19 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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