Created
October 26, 2018 10:29
-
-
Save mayojava/441c39db7c0d1943a8b09b5ea6f7890c to your computer and use it in GitHub Desktop.
Supervisor scope
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
| 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