Skip to content

Instantly share code, notes, and snippets.

@mayojava
Created October 26, 2018 10:29
Show Gist options
  • Select an option

  • Save mayojava/441c39db7c0d1943a8b09b5ea6f7890c to your computer and use it in GitHub Desktop.

Select an option

Save mayojava/441c39db7c0d1943a8b09b5ea6f7890c to your computer and use it in GitHub Desktop.
Supervisor scope
fun main() = runBlocking<Unit> {
launchChildren()
println("body of main")
}
suspend fun launchChildren() = supervisorScope {
launch(Dispatchers.Default) {
repeat(5) {
println("coroutine 1: count $it")
if(it == 2) {
throw ArithmeticException("not very nice error")
}
delay(500)
}
}
launch(Dispatchers.Default) {
repeat(5) {
println("coroutine 2: count $it")
delay(500)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment