You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd just like to ask a question: how can we know if the connection is closed by the client? I have a requirement where I need to notify other clients that have connected to the event stream at the time when a client sends a request to an endpoint.
So, let's say there's an endpoint of /api/broadcast, and a client made a request to it. The message should be broadcasted into clients that have connected to /api/stream.
The simplest implementation is to have a list of listeners that adds a new anonymous function when a client connected to /api/stream. That anonymous function will then have the Writer object and be able to send messages like writer.update(...). When a /api/broadcast is requested, it shall loop over the listeners and call them one-by-one, effectively sending the message across the subscribers of /api/stream.
But what if a client closes a connection to /api/stream? How can the server know to remove the listener from the list? It's getting kinda confusing. In next, the function just returns a Response and kind of forgets about it, how can we know anything about the connection?
Thanks a bunch!
The text was updated successfully, but these errors were encountered:
Hi! Thank you for this awesome project.
I'd just like to ask a question: how can we know if the connection is closed by the client? I have a requirement where I need to notify other clients that have connected to the event stream at the time when a client sends a request to an endpoint.
So, let's say there's an endpoint of
/api/broadcast
, and a client made a request to it. The message should be broadcasted into clients that have connected to/api/stream
.The simplest implementation is to have a list of listeners that adds a new anonymous function when a client connected to
/api/stream
. That anonymous function will then have theWriter
object and be able to send messages likewriter.update(...)
. When a/api/broadcast
is requested, it shall loop over the listeners and call them one-by-one, effectively sending the message across the subscribers of/api/stream
.But what if a client closes a connection to
/api/stream
? How can the server know to remove the listener from the list? It's getting kinda confusing. In next, the function just returns aResponse
and kind of forgets about it, how can we know anything about the connection?Thanks a bunch!
The text was updated successfully, but these errors were encountered: