-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Introduce interop between CoroutineContext and Reactor Context #284
Comments
@sdeleuze It makes total sense. They seem to fit conceptually. We can have |
This commit is the first part of a more complete Coroutines support coming in Spring Framework 5.2. It introduces suspendable Kotlin extensions for Mono based methods in WebFlux classes like WebClient, ServerRequest, ServerResponse as well as a Coroutines router usable via `coRouter { }`. Coroutines extensions use `await` prefix or `AndAwait` suffix, and most are using names close to their Reactive counterparts, except `exchange` in `WebClient.RequestHeadersSpec` which translates to `awaitResponse`. Upcoming expected changes are: - Leverage `Dispatchers.Unconfined` (Kotlin/kotlinx.coroutines#972) - Expose extensions for `Flux` based API (Kotlin/kotlinx.coroutines#254) - Introduce interop with `CoroutineContext` (Kotlin/kotlinx.coroutines#284) - Support Coroutines in `ReactiveAdapterRegistry` - Support Coroutines for WebFlux annotated controllers - Fix return type of Kotlin suspending functions (spring-projectsgh-21058) See spring-projectsgh-19975
Hi, any update on the integration of the related commit? |
@elizarov, @SokolovaMaria, @qwwdfsad Can you provide an update for this ? |
PR is on review, we are hopefully going to merge it to 1.3.0-RC |
@qwwdfsad, Sounds good. Thanks for update! |
Thanks for this first step, but I think this issue should be reopened for refinements before releasing 1.3 final. Based on my current understanding, with Coroutines 1.3.0-RC what is currently supported for Spring Framework use case is context interop for converting suspending function to For About In these example I have set the default value of Any thoughts? |
@sdeleuze can you, please, show a slightly more complete motivating example so that we have some sample code to verify our proposed solution against. |
@elizarov Sure, but you will have to wait next week since I am in vacation without any laptop. |
After a bit of discussion, we've decided to provide the following API:
context will be propagated to mono as long as
context is propagated to the original flux
For example, in the following snippet
the context will be propagated to flow body and, transitively, to someMono. We are planning to merge this change to the upcoming 1.3 this week. |
That sounds perfect, please let me know if you need more input from me. |
* Propagation of the coroutine context of await calls into Mono/Flux builder * Publisher.asFlow propagates coroutine context from `collect` call to the Publisher * Flow.asFlux transform Fixes #284
Will this solve the problem that I cannot access the ReactiveSecurityContextHolder.getContext fom a coroutine?
|
@eiswind Yes |
I tried the test above against the reactor-context branch and it still fails. I guess I have to do something to propagate the context? The value is provided in the Reactor Context (in real life this is done by spring security), and I can see the value in the CoroutineContext. But it does seem to get lost on the awaitFirstOrNull. After some investigation I found that the changes in Await.kt do not seem to be in this branch. So I guess I have to wait until everything is merged. |
@eiswind Works for me in |
Thx for the reply.
seems to be just the wrong way.
did the trick. |
Reactor Context seems similar to
CoroutineContext
, so I tend to think it should be interesting to upgradekotlinx-coroutines-reactor
for seamless integration between both.@elizarov Any thoughts?
The text was updated successfully, but these errors were encountered: