3 ms·
Very valid concerns I think, but it's not quite that bad. A few points: - Goroutines are not garbage collected. - In this case and many others, you can just u
by jkn 14y ago
Very valid concerns I think, but it's not quite that bad. A few points:
- Goroutines are not garbage collected.
- In this case and many others, you can just use a buffered channel. But of course in many other cases it doesn't solve the problem.
- If you solve this with a "quit" channel but don't use it, obviously you have a problem
- Several goroutines can try to send to the same "quit" channel. Make it buffered and have every goroutine try to send.
- In the case of several listeners, you can just close the channel and all receivers will return.
- However if you have several senders and several receivers on the "quit" channel, then you have a problem: closing a closed channel will panic.
See also:
https://groups.google.com/forum/?fromgroups=#!msg/golang-nuts/bfuwmhbZHYw/XQ5LkBCH5QMJ https://groups.google.com/forum/?fromgroups=#!msg/golang-nut...
https://groups.google.com/forum/?fromgroups=#!msg/golang-nuts/YmYGoco0hP4/QKcY2NBRE2oJ https://groups.google.com/forum/?fromgroups=#!msg/golang-nut...