From b93ce1cea5092dc4aff6fdfc7043fd5edb5f2aa6 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 21 Dec 2015 18:09:50 +0000 Subject: [PATCH] refactor: no need for GossipSender.sent --- mesh/gossip.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mesh/gossip.go b/mesh/gossip.go index c6196af9..5d4d1f17 100644 --- a/mesh/gossip.go +++ b/mesh/gossip.go @@ -32,11 +32,9 @@ type Gossiper interface { // Accumulates GossipData that needs to be sent to one destination, // and sends it when possible. type GossipSender struct { - send func(GossipData) - cell chan GossipData - // for testing - sent bool - flushch chan chan bool + send func(GossipData) + cell chan GossipData + flushch chan chan bool // for testing } func NewGossipSender(send func(GossipData)) *GossipSender { @@ -48,6 +46,7 @@ func NewGossipSender(send func(GossipData)) *GossipSender { } func (s *GossipSender) run() { + sent := false for { select { case pending := <-s.cell: @@ -55,18 +54,18 @@ func (s *GossipSender) run() { return } s.send(pending) - s.sent = true - case ch := <-s.flushch: + sent = true + case ch := <-s.flushch: // for testing // send anything pending, then reply back whether we sent // anything since previous flush select { case pending := <-s.cell: s.send(pending) - s.sent = true + sent = true default: } - ch <- s.sent - s.sent = false + ch <- sent + sent = false } } }