-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply contextCapture automatically in await
function
#3563
Comments
|
I have created a sample project. The code is in one file. You can start it with the following command.
|
await
function
I found that the following workaround can be done using the
package example
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.reactive.ContextInjector
import org.reactivestreams.Publisher
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import kotlin.coroutines.CoroutineContext
@OptIn(InternalCoroutinesApi::class)
class ContextCaptureInjector : ContextInjector {
override fun <T> injectCoroutineContext(publisher: Publisher<T>, coroutineContext: CoroutineContext): Publisher<T> {
return when (publisher) {
is Mono -> publisher.contextCapture()
is Flux -> publisher.contextCapture()
else -> publisher
}
}
} |
@be-hase please move reopen this ticket at kotlin side since we can nothing to do at the reactor one. Alternatively, the mentioned workaround could be landed there -> https://github.com/reactor/reactor-kotlin-extensions. Feel free to open PR |
OK, I'll reopen issue. thanks :) |
reopend here: reactor/reactor-kotlin-extensions#59 |
Motivation
This is a similar issue.
#3406
For users using kotlin coroutine, ThreadContextElement is used to propagate MDC, etc.
The block operator is supported by Hooks.automaticContextPropagation, but not the await function. Therefore, we are forced to write it this way.
It would be great if the await function is also supported, like the block operator.
...However, the await function is implemented on the coroutine side, so perhaps a request should be made on the coroutine side.
https://github.com/Kotlin/kotlinx.coroutines/blob/1ccc96890d38be52d1bdcd31af5befb54804aa05/reactive/kotlinx-coroutines-reactor/src/Mono.kt#L46
Desired solution
Considered alternatives
Additional context
The text was updated successfully, but these errors were encountered: