On Wed, Jun 15, 2016 at 12:25 PM, Eric Greer <integ...@gmail.com> wrote:
>
> Thanks for the reply. What I'm trying to do is to make a web socket server
> where all clients are sent broadcast messages. When the client connects, a
> channel is creates and registered in a global list of client channels. When
> a client disconnects, the channel gets closed. The broadcaster does not know
> and crashes.
>
> Is it possible to gracefully skip channels that are closed, or do I need to
> create a registry of clients that have their own IDs mapped to a channel so
> that I can prune them?  I ended up doing it this way and I realize that
> leaving closed channels in the list is memory bloat over time, but it would
> have saved a lot of time on this throw away program to just loop over a
> slice of channels.

Closing a channel is a send operation.  It's not closing a file or a
network connection.  It's not necessary to close a channel.  The only
reason to do so is to send a signal: that there will be no more data
on the channel.  For the receiver of a channel to close it is wrong.

You should keep the registry you mention, and at the point where today
you close the channel, you should instead remove the channel from the
registry.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to