.kotlinx.kotlinx-coroutines-reactor.1.8.1.source-code.ReactorContextInjector.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-coroutines-reactor Show documentation
Show all versions of kotlinx-coroutines-reactor Show documentation
Coroutines support libraries for Kotlin
package kotlinx.coroutines.reactor
import kotlinx.coroutines.reactive.*
import org.reactivestreams.*
import reactor.core.publisher.*
import reactor.util.context.*
import kotlin.coroutines.*
internal class ReactorContextInjector : ContextInjector {
/**
* Injects all values from the [ReactorContext] entry of the given coroutine context
* into the downstream [Context] of Reactor's [Publisher] instances of [Mono] or [Flux].
*/
override fun injectCoroutineContext(publisher: Publisher, coroutineContext: CoroutineContext): Publisher {
val reactorContext = coroutineContext[ReactorContext]?.context ?: return publisher
return when(publisher) {
is Mono -> publisher.contextWrite(reactorContext)
is Flux -> publisher.contextWrite(reactorContext)
else -> publisher
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy