Exerosis
03/30/2022, 1:14 AMsuspend fun debug() {
println("${coroutineContext[STreeEvent]}")
}
fun main() = runBlocking {
val test = SSubject(0)
SComponent().apply {
println("Component: $this")
println("Test: $test")
test(this, BEFORE) {
println("${coroutineContext[STreeEvent]}")
debug()
}
...
Can someone help me understand why :
println("${coroutineContext[STreeEvent]}")
debug()
prints:
null
1212899836
Why on earth would the context change between these two places?ephemient
03/30/2022, 1:24 AMExerosis
03/30/2022, 1:25 AMRichard Gomez
03/30/2022, 2:06 AM- suspend fun debug() {
+ suspend fun debug(): Unit = coroutineScope {
ephemient
03/30/2022, 2:10 AMcoroutineScope {
println(...)
debug()
}
Richard Gomez
03/30/2022, 2:37 AMthe problem is the other way around,You're right, I misread that. Long day... 😴
Joffrey
03/30/2022, 6:04 AMcoroutineContext
when you want the one from the current suspend function, use currentCoroutineContext()
instead in this caseExerosis
03/31/2022, 3:20 AMephemient
03/31/2022, 3:22 AMExerosis
04/05/2022, 3:43 AM