Skip to content

Instantly share code, notes, and snippets.

@shiehnpin
Created July 27, 2020 04:51
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 shiehnpin/f0f4a59f85e273829494b85351f75c99 to your computer and use it in GitHub Desktop.
Save shiehnpin/f0f4a59f85e273829494b85351f75c99 to your computer and use it in GitHub Desktop.
@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)
}
}
@shiehnpin
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment