another questions about MDC and coroutineContext.....
# coroutines
another questions about MDC and coroutineContext.. can i update a ThreadContextElement from inside the coroutine ? issue is this code seems natural
Copy code
suspend fun doStuff() = withContext(MDCContext() + exceptionHandler()) {
   MDC.put("flow", "do-stuff")
   <|> { "doing stuff" } // mdc is fine here


   <|> { "done doing stuff" } // mdc was reset to the state of MDCContext ie. is empty
ideally what i would like to be able to do is update the MDCContext or update the
val contextMap: MDCContextMap
after i modify the MDC ( i tried, it fails in different ways ) or use a mechanism where the MDC is stored before doing a suspend call, so any changes are actually picked up TL;DR currently it leads to rather unnatural looking code and additional nesting or errors that are really hard to find
You cannot use put, it will be rested after suspend
It mentioned in doc
Take the current MDCcontext, mutate and modify it, and wrap your suspend fun with one more withContext
exactly that extra withContext is what i was hoping to avoid, making code really a lot more annoying to write and read
Maybe create an extension function for it?