I have a process that is basically part of a long polling implementation. In a nutshell, the client makes a request to the server, which then creates a channel and returns it to that client. The channel will contain the information that client asked for. Because this is intended to be used for long polling, the information that the client has requested can change. If the information changes, the server will write the update to the channel, and in theory, the client can grab the update and reflect that.
The problem I am facing is that there is a chance that I end up with tons of channels, which can cause unnecessary processing when an update occurs. I could potentially be updating channels where the client no longer cares.
My solution was that once the client stops caring about the information, it closes the channel, which will somehow notify the server, and prevent the server from doing additional processing and updates.
How can the server know if a channel is closed? In this scenario, the server is essentially a writer and does not read anything from the channel. Also, all the writing methods are wrapped in a go block, so it always returns a channel (I don't see any nils). Is there a way to do this, or is my approach completely off?
Thanks