cosmetic
This commit is contained in:
1 parent
592335092c
commit
3be28523c9
1 file changed
+21
-25
+21
-25
@@ -42,51 +42,47 @@ type GossipSender struct {
|
|||||||
func NewGossipSender(send func(GossipData)) *GossipSender {
|
func NewGossipSender(send func(GossipData)) *GossipSender {
|
||||||
cell := make(chan GossipData, 1)
|
cell := make(chan GossipData, 1)
|
||||||
flushch := make(chan chan bool)
|
flushch := make(chan chan bool)
|
||||||
sender := &GossipSender{
|
s := &GossipSender{send: send, cell: cell, flushch: flushch}
|
||||||
send: send,
|
go s.run()
|
||||||
cell: cell,
|
return s
|
||||||
flushch: flushch,
|
|
||||||
}
|
|
||||||
go sender.run()
|
|
||||||
return sender
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sender *GossipSender) run() {
|
func (s *GossipSender) run() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case pending := <-sender.cell:
|
case pending := <-s.cell:
|
||||||
if pending == nil { // receive zero value when chan is closed
|
if pending == nil { // receive zero value when chan is closed
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sender.send(pending)
|
s.send(pending)
|
||||||
sender.sent = true
|
s.sent = true
|
||||||
case ch := <-sender.flushch:
|
case ch := <-s.flushch:
|
||||||
// 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 := <-sender.cell:
|
case pending := <-s.cell:
|
||||||
sender.send(pending)
|
s.send(pending)
|
||||||
sender.sent = true
|
s.sent = true
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
ch <- sender.sent
|
ch <- s.sent
|
||||||
sender.sent = false
|
s.sent = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sender *GossipSender) Send(data GossipData) {
|
func (s *GossipSender) Send(data GossipData) {
|
||||||
// NB: this must not be invoked concurrently
|
// NB: this must not be invoked concurrently
|
||||||
select {
|
select {
|
||||||
case pending := <-sender.cell:
|
case pending := <-s.cell:
|
||||||
sender.cell <- pending.Merge(data)
|
s.cell <- pending.Merge(data)
|
||||||
default:
|
default:
|
||||||
sender.cell <- data
|
s.cell <- data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sender *GossipSender) Stop() {
|
func (s *GossipSender) Stop() {
|
||||||
close(sender.cell)
|
close(s.cell)
|
||||||
}
|
}
|
||||||
|
|
||||||
type GossipChannels map[string]*GossipChannel
|
type GossipChannels map[string]*GossipChannel
|
||||||
@@ -163,8 +159,8 @@ func (router *Router) sendPendingGossip() bool {
|
|||||||
return sentSomething
|
return sentSomething
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sender *GossipSender) flush() bool {
|
func (s *GossipSender) flush() bool {
|
||||||
ch := make(chan bool)
|
ch := make(chan bool)
|
||||||
sender.flushch <- ch
|
s.flushch <- ch
|
||||||
return <-ch
|
return <-ch
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user