Looking forward to the coroutine support in Spring...
# spring
j
Looking forward to the coroutine support in Spring MVC - We can then finally get rid of our
runBlocking
"workaround" - thanks @sdeleuze ! Less Kotlin, probably more about Spring itself: We're also using functional routing for a year now and we're very happy with it. The only thing I miss is support for server side events for Spring MVC projects. The functional routing receives a
ServerRequest
and expects a
ServerResponse
in return but I don't see a way to incorporate to respond with the SseEmitter object that is used for SSE on Spring MVC. Am I missing something or should I open a ticket?
👍 1
s
For Coroutines support in Spring MVC, that will be much better than runBlocking because it will not block Tomcat thread, it will use Spring MVC async support.
For SSE in WebMvc.fn, indeed I think it is missing but I think we could add it, see https://github.com/spring-projects/spring-framework/issues/25920.
j
thank you!
Regarding the Coroutine support: could WebMvc.fn be adjusted to support the suspending functions as well? With a little bit of guidance I could work on a PR to add it e.g. • if it's possible at all • if a coRouter for servlet environments would be better than adjusting the router DSL to accept suspending functions as well
s
For WebMvc.fn I don't think a
coRouter
would make sense but maybe a
ServerResponse.async
extension taking a suspending function as parameter? That would be the Coroutines variant for
static ServerResponse async(Object asyncResponse)
.
j
I'll try 👍
could you point me to where suspended functions are handled? I'm wondering if they get 'converted' to CompleteableFuture to use with ServerResponse.async EDIT: seems to be https://github.com/spring-projects/spring-framework/blob/master/spring-core/kotlin-coroutines/src/main/kotlin/org/springframework/core/CoroutinesUtils.kt
s
Yep
j
I'm currently testing this:
Copy code
fun test(request: ServerRequest): ServerResponse {

        return ServerResponse.async(mono(Dispatchers.Unconfined) {
            throw ResponseStatusException(HttpStatus.BAD_GATEWAY)
        })
    }
the exception is swallowed, resulting in a HTTP 200 while the logs show
javax.servlet.ServletException: javax.servlet.ServletException: org.springframework.web.server.ResponseStatusException
will I have to invoke Springs internal exception handling system (that renders ResponseStatusException to their HTTP codes) manually?
if I solve this, the proof of concept (and PR) for handling suspending functions in WebMvc.fn can easily be made 🙂