Last active
December 14, 2018 12:27
-
-
Save kevinherron/37155732ccd4c0587a69a9d86e16b448 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.* | |
fun main(args: Array<String>) { | |
val job = SupervisorJob() | |
val scope = CoroutineScope(job + Dispatchers.Default) | |
val deferred = GlobalScope.async(Dispatchers.Default, start = CoroutineStart.LAZY) { | |
delay(5000) | |
throw Exception("boom") | |
} | |
scope.launch { | |
try { | |
deferred.await() | |
} catch (e: Exception) { | |
println("error awaiting: $e") | |
} | |
} | |
runBlocking { job.cancelAndJoin() } | |
Thread.sleep(10000) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment