hono icon indicating copy to clipboard operation
hono copied to clipboard

Export SSEMessage and SSEStreamingApi from hono/streaming

Open donchev7 opened this issue 1 year ago • 3 comments

What is the feature you are proposing?

Currently hono/streaming only exports streamSSE. It would be nice to export SSEStreamingApi and SSEMessage so that we can write functions outside and not needing inlining the callback. For example:

const myStreamingLogic = async (stream: SSEStreamingApi) => {
   // do business logic
}

in the handler:

const createMessageHandler = async (c: Context) => {
  return streamSSE(c, myStreamingLogic)
}

donchev7 avatar Dec 23 '23 15:12 donchev7

StreamingAPI is exported like this, I see.

https://github.com/honojs/hono/blob/a8fb2377c90de6f216135a4bb3c2bd1704c1086f/src/utils/stream.ts#L1-L10

If it's acceptable, I can make the modifications. Are there any other opinions on this? @yusukebe @sor4chi

watany-dev avatar Dec 25 '23 02:12 watany-dev

Hi, @watany-dev @donchev7 How about providing it as factory.createStreamHandler and factory.createStreamSSEHandler? cc: @yusukebe

sor4chi avatar Dec 25 '23 02:12 sor4chi

How about providing it as factory.createStreamHandler and factory.createStreamSSEHandler?

I don't think we need to go that far.

It' enough to just export SSEStreamingApi and SSEMessage.

yusukebe avatar Dec 25 '23 03:12 yusukebe

This can be closed!

yusukebe avatar Mar 25 '24 18:03 yusukebe