Skip to content

Instantly share code, notes, and snippets.

@kevinherron
Last active December 14, 2018 12:27
Show Gist options
  • Save kevinherron/37155732ccd4c0587a69a9d86e16b448 to your computer and use it in GitHub Desktop.
Save kevinherron/37155732ccd4c0587a69a9d86e16b448 to your computer and use it in GitHub Desktop.
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