Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QnA: What if the connection is closed by the client? #86

Open
iyxan23 opened this issue May 10, 2024 · 0 comments
Open

QnA: What if the connection is closed by the client? #86

iyxan23 opened this issue May 10, 2024 · 0 comments

Comments

@iyxan23
Copy link

iyxan23 commented May 10, 2024

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 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant