Skip to content

Instantly share code, notes, and snippets.

@houssemzaier
Last active September 2, 2020 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save houssemzaier/b5ff46b3208e8258363883cc5930eb81 to your computer and use it in GitHub Desktop.
Save houssemzaier/b5ff46b3208e8258363883cc5930eb81 to your computer and use it in GitHub Desktop.
Testing Effect on children When Canceling Parent job
package fr.francetv.francetvsport.arch.presentation.videodetail
import kotlinx.coroutines.*
fun main() = runBlocking {
val parentJob = launch {
launch {
println("start launch child")
while (isActive) {
delay(500)
println("... working in launch child")
}
println("end launch child")
}
launch {
supervisorScope {
println("start supervisorScope child")
while (isActive) {
delay(500)
println("... working in supervisorScope child")
}
println("end supervisorScope child")
}
}
launch {
coroutineScope {
println("start coroutineScope child")
while (isActive) {
delay(500)
println("... working in coroutineScope child")
}
println("end coroutineScope child")
}
}
launch {
withContext(Dispatchers.IO) {
println("start withContext child")
while (isActive) {
delay(500)
println("... working in withContext child")
}
println("end withContext child")
}
}
launch {
runBlocking {
println("start runBlocking child")
while (isActive) {
delay(5_000)
println("... working in runBlocking child")
}
println("end runBlocking child")
}
}
}
launch {
println("start parallel launch child")
delay(2_000)
parentJob.cancel()
println("end parallel launch child")
}
parentJob.join()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment