I'm trying to follow the docs to make a legal thre...
# coroutines
j
I'm trying to follow the docs to make a legal threadlocal update in a singlet-threaded test. despite my best asttempts to create a context element and set() the new value i only receive the initial state on successive calls. what am i missing ?
@elizarov the docs for
Copy code
tl.asContextElement()
seem ambiguous about whther this call reifies a handle to parent or a local scoped copy. the latter appears to be the case when the former might be implied.
in my posted debugger case I am able to capture the return value as the new state with
.also(state::set)
on the outermost return and see the modified threadlocal re-enter but I am curious why the context element promotion should not simply map the parent scope get/set methods as parent state accessors. the documentation appears to speak only on behalf of creating locally scoped bubble contexts which gives no commentary on interacting with the parent scope or explicit Global context measures to avoid undefined access to parent handle
b
Don't you need to pull the thread local from the context instead of a wrapped reference? (I don't use them, but haven't seen any other responses, yet)
j
what i know is that I have class foo with val state:ThreadLocal<Something> ensurePresent is only possible on a context element. when i call the context-element.set(newval) i get initial value next time. when i leave the coroutinescope and call state.set() it works after the result of gratuitious runBlocking inner scope use. what i have not done is attempt this on suspending code. right now context state is a placeholder for parralell refactorings down the road. maybe there are some algebraic laws of concurrency that make a handle to a ThreadLocal undefined. in my usecase i guess i need to promote my threadlocal to a coroutinecontext that i pass around.