I have a TCP socket and 2 goroutines reading and writing to streams. I am writing a goroutine that reads data from a channel. If the TCP connection is dropped then the read from the go routine will detect an error and stop.
But how do I release a channel that has a goroutine writing to?
Is there method like chan.release()
or should I post a special packet that will tell the goroutine to end?
close(ch)
will close the channel.
If you are ranging over the channel then the for loop will exit when the channel is closed. val, ok := <-ch
allow you to check for closed channels. ok will be a boolean value with false if the ch is closed true if the ch is open.