Skip to content

Commit

Permalink
move wg.Done() into a defer
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjbrettj committed Oct 31, 2024
1 parent 55318db commit 6625430
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/grandpa/neighbor_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
)

// How often neighbor messages should be rebroadcast in the case where no new packets are created
// How often neighbour messages should be rebroadcast in the case where no new packets are created
const neighbourBroadcastPeriod = time.Minute * 2

type neighborData struct {
Expand Down Expand Up @@ -52,13 +52,8 @@ func newNeighborTracker(grandpa *Service, neighborChan chan neighborData) *neigh
}

func (nt *neighborTracker) Start() {
//go nt.run()

nt.wg.Add(1)
go func() {
nt.run()
nt.wg.Done()
}()
go nt.run()
}

func (nt *neighborTracker) Stop() {
Expand All @@ -71,7 +66,10 @@ func (nt *neighborTracker) Stop() {
func (nt *neighborTracker) run() {
logger.Info("starting neighbour tracker")
ticker := time.NewTicker(neighbourBroadcastPeriod)
defer ticker.Stop()
defer func() {
ticker.Stop()
nt.wg.Done()
}()

for {
select {
Expand Down

0 comments on commit 6625430

Please sign in to comment.