refactor: no need for GossipSender.sent

This commit is contained in:
Matthias Radestock committed 2015-12-21 18:09:50 +00:00
1 parent 3be28523c9
commit b93ce1cea5
1 file changed
+9 -10
+9 -10
View File
@@ -32,11 +32,9 @@ type Gossiper interface {
// Accumulates GossipData that needs to be sent to one destination, // Accumulates GossipData that needs to be sent to one destination,
// and sends it when possible. // and sends it when possible.
type GossipSender struct { type GossipSender struct {
send func(GossipData) send func(GossipData)
cell chan GossipData cell chan GossipData
// for testing flushch chan chan bool // for testing
sent bool
flushch chan chan bool
} }
func NewGossipSender(send func(GossipData)) *GossipSender { func NewGossipSender(send func(GossipData)) *GossipSender {
@@ -48,6 +46,7 @@ func NewGossipSender(send func(GossipData)) *GossipSender {
} }
func (s *GossipSender) run() { func (s *GossipSender) run() {
sent := false
for { for {
select { select {
case pending := <-s.cell: case pending := <-s.cell:
@@ -55,18 +54,18 @@ func (s *GossipSender) run() {
return return
} }
s.send(pending) s.send(pending)
s.sent = true sent = true
case ch := <-s.flushch: case ch := <-s.flushch: // for testing
// send anything pending, then reply back whether we sent // send anything pending, then reply back whether we sent
// anything since previous flush // anything since previous flush
select { select {
case pending := <-s.cell: case pending := <-s.cell:
s.send(pending) s.send(pending)
s.sent = true sent = true
default: default:
} }
ch <- s.sent ch <- sent
s.sent = false sent = false
} }
} }
} }