Skip to content

Instantly share code, notes, and snippets.

@Megaprog
Created December 1, 2021 10:47
Show Gist options
  • Save Megaprog/5a858fb707034dc59a64dbc2c413376a to your computer and use it in GitHub Desktop.
Save Megaprog/5a858fb707034dc59a64dbc2c413376a to your computer and use it in GitHub Desktop.
CoroutineScope(coroutineContext + SupervisorJob()) and supervisorScope() look simular but behaviur is completly different. If you add SupervisorJob() then all jobs will be out of scope and when nobody will wait for them after scope finishes
fun main() {
runBlocking {
repeat(10) {
try {
// CoroutineScope(coroutineContext + SupervisorJob()).run {
supervisorScope {
listOf(
async {
throw IllegalStateException("ERROR OCCURRED.")
},
async {
delay(2000)
println("123")
}
)
}.awaitAll()
} catch (e: Exception) {
println(e)
}
}
delay(1000)
}
Thread.sleep(10000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment