https://kotlinlang.org logo
#coroutines
Title
# coroutines
e

Evgeniy Zaharov

11/11/2020, 2:06 PM
Hi, I have a problem with switching from ReactorContext to CoroutineContext In coroutine-reactor docs I found an example:
Copy code
val flow = flow<Unit> {
   println("Reactor context in Flow: " + coroutineContext[ReactorContext])
}

flow.asFlux()
    .subscriberContext { ctx -> ctx.put("answer", 42) }
    .subscribe() // Must print "Reactor context in Flow: Context{'answer'=42}" but print "Reactor context in Flow: null"
But with coroutine 1.4.0, 1.4.1 it prints Null. Am I miss something?
found a workaround
Copy code
val flow = flow<Unit> {
            println("Reactor context in Flow: " + coroutineContext[ReactorContext])
            val context = Mono.deferWithContext { ctx -> Mono.just(ctx) }.awaitFirst()
            println("Reactor context from defer: $context")
        }
        flow.asFlux()
            .subscriberContext { ctx -> ctx.put("answer", 42) }
            .subscribe()
it will prints:
Copy code
Reactor context in Flow: null
Reactor context from defer: Context1{answer=42}
22 Views