mommde
08/11/2023, 11:07 PMvar testScope: CoroutineContext?
get() = null
set(value) {}
fun Route.kotlinSuperiority() {
get {
testScope = this.coroutineContext
println(testScope)
println(this@get.coroutineContext)
println("why?")
}
}
the results are
null
[io.ktor.server.engine.DefaultUncaughtExceptionHandler@1f751406, CoroutineName(request-handler), ScopeCoroutine{Active}@22ddec7a, <http://Dispatchers.IO]|Dispatchers.IO]>
why?
so my question is why my outer scope variable isn't beeing set to the CoroutineContext (and if there is a way to workaround). I could only imagine some weird threading phenomenon i don't understand.
Thanks ~Moritz
(and i hope i am in the right channel)asdf asdf
08/12/2023, 4:36 AMfield = value
somewhere in the setter body in order for the backing field to be updated, which also means it needs to be initialized with = null
. Same thing with the getter, it’s always returning null.
If the get/set accessors aren’t actually doing anything other than getting/setting the field then you really don’t need them at all and can just have var testScope: CoroutineContext? = null
.mommde
08/12/2023, 10:38 AM