Last active
September 2, 2020 20:04
-
-
Save houssemzaier/b5ff46b3208e8258363883cc5930eb81 to your computer and use it in GitHub Desktop.
Testing Effect on children When Canceling Parent job
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
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