Created
July 27, 2020 04:51
-
-
Save shiehnpin/f0f4a59f85e273829494b85351f75c99 to your computer and use it in GitHub Desktop.
This file contains 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
@Test | |
fun test() = runBlocking<Unit>(Dispatchers.Default) { | |
var job1: Job? = null | |
var job2: Job? = null | |
coroutineScope { | |
var c1:CoroutineContext? = null | |
var c2:CoroutineContext? = null | |
job1 = launch { | |
c1 = coroutineContext | |
println("${c1!![Job]}") | |
delay(1000) | |
println("end job1") | |
} | |
job2 = launch { | |
c2 = coroutineContext | |
println("${c2!![Job]}") | |
delay(1000) | |
println("end job2") | |
} | |
delay(100) | |
val combineContext = c1!!+c2!! | |
println(c1) | |
println(c2) | |
println(combineContext) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
console:
"coroutine#2":StandaloneCoroutine{Active}@1c4a92c
"coroutine#3":StandaloneCoroutine{Active}@65ddbd41
[CoroutineId(2), "coroutine#2":StandaloneCoroutine{Active}@1c4a92c, DefaultDispatcher]
[CoroutineId(3), "coroutine#3":StandaloneCoroutine{Active}@65ddbd41, DefaultDispatcher]
[CoroutineId(3), "coroutine#3":StandaloneCoroutine{Active}@65ddbd41, DefaultDispatcher]
end job1
end job2