Close the melt channel, don't just send once on it.

Closing the channel makes it always immediately selectable.
This commit is contained in:
David Fifield 2019-12-24 19:22:48 -07:00
parent febb4936f6
commit f1ab65b1c0

View file

@ -35,7 +35,7 @@ func NewPeers(max int) *Peers {
// Use buffered go channel to pass snowflakes onwards to the SOCKS handler. // Use buffered go channel to pass snowflakes onwards to the SOCKS handler.
p.snowflakeChan = make(chan Snowflake, max) p.snowflakeChan = make(chan Snowflake, max)
p.activePeers = list.New() p.activePeers = list.New()
p.melt = make(chan struct{}, 1) p.melt = make(chan struct{})
return p return p
} }
@ -110,7 +110,7 @@ func (p *Peers) purgeClosedPeers() {
// Close all Peers contained here. // Close all Peers contained here.
func (p *Peers) End() { func (p *Peers) End() {
close(p.snowflakeChan) close(p.snowflakeChan)
p.melt <- struct{}{} close(p.melt)
cnt := p.Count() cnt := p.Count()
for e := p.activePeers.Front(); e != nil; { for e := p.activePeers.Front(); e != nil; {
next := e.Next() next := e.Next()