refactor: introduce a helper

which has a very narrow purpose, and can use 'defer' to release the
lock, which is nice.
This commit is contained in:
Matthias Radestock committed 2015-12-30 12:09:19 +00:00
1 parent a2b192c472
commit e9520215a0
1 file changed
+9 -6
+9 -6
View File
@@ -184,11 +184,18 @@ func (c *GossipChannel) relay(srcName PeerName, data GossipData) {
}
func (c *GossipChannel) sendDown(conns []Connection, data GossipData) {
for _, sender := range c.sendersFor(conns) {
sender.Send(data)
}
}
func (c *GossipChannel) sendersFor(conns []Connection) []*GossipSender {
if len(conns) == 0 {
return
return nil
}
ourConnections := c.ourself.Connections()
c.Lock()
defer c.Unlock()
// GC - randomly (courtesy of go's map iterator) pick some
// existing senders and stop&remove them if the associated
// connection is no longer active. We stop as soon as we
@@ -218,11 +225,7 @@ func (c *GossipChannel) sendDown(conns []Connection, data GossipData) {
}
senders[i] = sender
}
c.Unlock()
// send
for _, sender := range senders {
sender.Send(data)
}
return senders
}
func (c *GossipChannel) makeSender(conn Connection) *GossipSender {