-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Hello,
First of all, thank you very much for creating this gem — I really appreciate your work.
I would like to discuss the current behavior of SSE::Client.
Right now, SSE::Client always runs asynchronously, but I believe there are cases where an SSE client should behave synchronously. For example, if the architecture looks like:
AI <—> Backend Server <—> Frontend
there may be situations where the backend needs to wait for SSE responses and also return SSE responses to the frontend at the same time.
However, because the current implementation always runs asynchronously in a separate thread, the backend logic finishes immediately, making synchronous flow impossible.
Additionally, in read_stream, when data is nil, the code breaks out of the loop — which makes sense — but I think it should also explicitly call close to properly close the SSE connection.
If I’m misunderstanding something about SSE in general, I apologize.
I would really appreciate hearing your thoughts on these points.
Thank you very much.
module SSE
class Client
def initialize(..., async: true)
if async
thread = Thread.new { run_stream }
thread.name = THREAD_NAME
else
run_stream
end
end
end
end