Conversation
fixes the case when fiber is manually killed while waiting
megatux
left a comment
There was a problem hiding this comment.
I think it looks great.
I have some questions. Regarding the pub/sub stuff or the rage-iodine gem update, are they strictly part of this SSE support or are things that can be part of separated PRs?
Also, I guess we need spec tests for this new controller functionality
|
Thanks - really appreciate you taking the time to look through this 🙏 A bit of context: this PR is more of a foundation step than a release candidate. I've been designing SSE support for a while, and what's here is the initial end-to-end integration, but it's not production-ready yet. I expect it will need several more weeks of hardening (performance testing, edge cases, etc.) before I'm comfortable cutting a release. To answer your questions regarding the scope:
If you want to experiment early, I'd recommend bundling directly from GitHub for now. Once I'm confident in stability and performance, I'll cut a proper release. I'm trying to be very deliberate with new primitives like this - once they're public API, they're very hard to change. So I'd rather take the time now than rush something half-baked. Feedback on the design is very welcome though. |
reducing the scope - streams will go into a separate PR
|
Hi @megatux This has been merged and release in v1.22.0! |
Native Server-Sent Events (SSE) Support
This PR adds native support for server-sent events, enabling real-time, server-to-client streaming over HTTP with a simple, idiomatic API.
Why SSE?
Server-Sent Events provide a lightweight alternative to WebSockets when you only need server-to-client communication - think live notifications, activity feeds, progress updates, or streaming AI responses. Unlike WebSockets, SSE works over standard HTTP, plays nicely with existing infrastructure (load balancers, proxies, CDNs), and automatically handles reconnection out of the box.
Rage now makes SSE a first-class citizen with three approaches depending on your use case:
Streams
Use
Enumeratorobjects to stream events as they're generated. This is ideal for sequential data or when the server controls the pace:For more control, create a custom enumerator - useful for long-running computations, database cursors, or AI token streaming:
Pub/SubThe pub/sub functionality will be delivered in the next PR.
When events originate from background jobs, other services, or different parts of your application, useRage::SSE::Streamto decouple the connection from the event source:Then broadcast from anywhere:One-off Updates
For simple cases where you just need to push a single payload over SSE (e.g., compatibility with SSE-only clients):
Rich Message Support
Use
Rage::SSE.messageto include SSE metadata like event types, IDs for resumption, and retry intervals:Low-level Access
For advanced use cases requiring full control over the connection lifecycle and wire format, pass a proc:
In this mode, Rage hands you the raw connection - you're responsible for formatting and cleanup.
❗ Depends on rage-rb/iodine#9.