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. Thanks again for the reply. On Wed, Jun 15, 2016, 8:00 AM Ian Lance Taylor <i...@golang.org> wrote: > On Tue, Jun 14, 2016 at 10:15 PM, <integ...@gmail.com> wrote: > > > > What happens if the channel closes? > > > > I'm thinking about maintaining a list of channels (one for each websocket > > client), then sending a message to all of them. The only problem is that > > when the websocket client disconnects, their channel closes. Being > there no > > easy way to skip closed channels, the program crashes. > > To be clear, I assume that we are talking about the Go chan type. > > Closing a channel is a send operation, and only the sender should > close a channel. So I'm not sure what you mean when you that when the > websocket client disconnects, their channel closes. If you are > sending a message to the client, then the client should not close the > channel. > > 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.