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:
1 parent
a2b192c472
commit
e9520215a0
1 file changed
+9
-6
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user