Skip to content

Commit

Permalink
Add timedout channel send, change ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
gdiazlo committed Mar 6, 2019
1 parent 430e337 commit 134c0b3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions gossip/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ func NewAgent(conf *Config, p []Processor) (agent *Agent, err error) {

return agent, nil
}
func chTimedSend(batch *protocol.BatchSnapshots, ch chan *protocol.BatchSnapshots) {
for {
select {
case <-time.After(200 * time.Millisecond):
log.Infof("Timed out sending out batch ")
return
case ch <- batch:
return
}
}
}

func (a *Agent) start() {
outTicker := time.NewTicker(2 * time.Second)
Expand All @@ -115,7 +126,7 @@ func (a *Agent) start() {
for _, p := range a.processors {
go p.Process(*batch)
}
a.Out <- batch
chTimedSend(batch, a.Out)
case <-outTicker.C:
go a.sendOutQueue()
case <-a.quit:
Expand All @@ -141,7 +152,7 @@ func (a *Agent) sendOutQueue() {
continue
}

batch.TTL--
batch.TTL -= 1
from := batch.From
batch.From = a.Self
msg, _ := batch.Encode()
Expand Down

0 comments on commit 134c0b3

Please sign in to comment.