-
Notifications
You must be signed in to change notification settings - Fork 38.1k
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
Add support for Kotlin coroutines [SPR-15413] #19975
Comments
Konrad Kamiński commented I created a pull request. |
Sébastien Deleuze commented Thanks for contributing this pull request. Kotlin coroutines seems indeed a good fit for I would suggest submitting a similar pull request on kotlinx.coroutines in order to provide such support like it has been done for Reactor |
Sébastien Deleuze commented Konrad Kamiński I turn this issue into a global coroutine support one, since there may be other areas than Did you experiment with coroutines + Spring WebFlux? After reading the guide to reactive streams with coroutines, it seems to me this is something worth to explore if we can leverage the existing Reactor based infrastructure of Spring WebFlux (via annotation or functional API) to provide the ability to use imperative style code for those who are not confortable with functional APIs. That said we really need to experiment in order to see how this work with backpressure, see if it can enable easily to implement custom operator as advertised, etc. Any sample WebFlux + coroutine application example could help to move this topic forward. |
Konrad Kamiński commented I created a proof-of-concept implementation of mixit application with coroutines. I have not yet touched either
In this poc I only covered whatever was needed for the |
Sébastien Deleuze commented That's super useful Konrad Kamiński thank you! I will have a deeper look to this branch and send you my feedback. |
Sébastien Deleuze commented I have submitted a pull-request on kotlinx.coroutines to upgrade Reactor coroutine support from |
Sébastien Deleuze commented Reactor Bismuth and Spring Framework 5 support is now available as part of kotlinx.coroutines 0.19.1. |
Sébastien Deleuze commented Konrad Kamiński Now that Spring Framework 5 and Reactor Core 3.1 are GA + are supported in |
Sébastien Deleuze commented Some additional thoughts about bridging Reactor-based APIs to Coroutines based on your previous experiment. For streaming use case, For non streaming use cases, maybe most of the time translating
|
Sébastien Deleuze commented See this PR comment. |
Sébastien Deleuze commented A quick update:
|
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
Coroutines support for Coroutines extensions use Upcoming expected changes are:
I am also preparing pull-requests for Spring Data MongoDB and Spring Data R2DBC. A demo project is available in this spring-boot-coroutines-demo repository. |
This commit turns Coroutines suspending methods to `Mono` which can be handled natively by WebFlux. See spring-projectsgh-19975
Support for WebFlux annotated controllers, including view resolution and |
This commit introduces the spring-core-coroutines module in order to avoid referencing Kotlin code from Java one, which is currently not supported by Eclipse. During the build, spring-core-coroutines is merged into spring-core, so this change is expected to have no impact for end users. This module contains functions accessible from Java via the CoroutinesUtils class to adapt Coroutines and Deferred instances to and from Mono. See spring-projectsgh-19975
As of Coroutines 1.2.0-alpha, Dispatchers.Unconfined is a stable API so we can leverage it in order to get better performance in our Reactive to Coroutines bridge. See spring-projectsgh-19975
This commit provides both nullable and non-nullable variants for awaitBody, makes awaitPrincipal return type nullable and rename awaitResponse to awaitExchange for better consistency with Java API. See spring-projectsgh-19975
This commit also switches on kotlin-compiler-embeddable to improve isolation of its dependencies See spring-projectsgh-19975
As of Coroutines 1.2.0-alpha, Dispatchers.Unconfined is a stable API so we can leverage it in order to get better performances in our Reactive to Coroutines bridge. See spring-projectsgh-19975
With Coroutines
A detailed blog post is coming next week to present an overview of Spring Coroutines support. |
Konrad Kamiński opened SPR-15413 and commented
Since
1.1
Kotlin supports coroutines. Its library support includes utility functions for converting suspending functions/lambdas to/from CompletableFuture / Deferred. It would be nice to have such support ListenableFuture as well.The API could look as follows:
Affects: 5.0 M5
Issue Links:
Referenced from: pull request #1375
18 votes, 26 watchers
The text was updated successfully, but these errors were encountered: