Enhancement: Support for returning AsyncGenerator[ServerSentEventMessage, None]
at route handler
#3851
Labels
Enhancement
This is a new feature or request
Summary
Currently, Litestar forces you to create an intermediary function that yields
ServerSentEventMessage
then wrap the generator inServerSentEvent
.This is not an ideal pattern as you now have a method that isn't a route handler in your controller. If you were to abstract it out as a function, you'll now have to find an elegant place to define this function. In any case, this is an annoying problem.
Basic Example
Ideally, this is what you'd want. It has good code locality and you don't have to jump through functions or files to understand the full context of the code.
Drawbacks and Impact
I have a pseudo solution to this using decorators that has zero runtime cost aside from the initial injection at startup. Ideally, the actual solution should not have to depend on any decorators.
With this solution, I am still able to correctly generate OpenAPI docs and have no issues with DI. I am quite confident that this can be implemented without issues. If you know of any potential drawbacks, I'd like to hear it.
Unresolved questions
No response
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh dashboard
The text was updated successfully, but these errors were encountered: