Improving SSE handling for better extensibility #3472
-
I'm working on a small Deno server that I want to essentially lift some logic out our app and into a Server-Sent Event client (we only need one-way, so Websockets feel overkill for this) The app uses https://viem.sh/docs/actions/public/watchBlocks#usage and my thinking is to have this Something like app.get("/sse", async (c) => {
const target = c.sendEvents();
const unwatch = publicClient.watchBlocks(
{ onBlock: block => target.dispatchMessage(block); }
)
target.addEventListener("close", (evt) => {
unwatch()
});
// ...
}) This takes the API from Oak (https://oakserver.github.io/oak/sse.html) on how they handle server sent events which seems to be quite flexible compared to the streamSSE helper from Hono (https://hono.dev/docs/helpers/streaming#streamsse) There doesn't seem to be a way to have these long-running watch functions that output data in intervals due to the streamSSE requiring the stream.sleep() function otherwise it closes the connection (from what I understand reading other issues about SSE in Hono's context) Would love to see what y'all have any idea on how to solve this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I think you're talking about two different things. Additionally, hono has an Event Emitter middleware for Hono |
Beta Was this translation helpful? Give feedback.
The hono official could indeed support this. Maybe you could open a feature request?