Codebase list golang-github-go-kit-kit / 2a823da
Ditching mutexes for a waitgroup Martin Baillie 6 years ago
1 changed file(s) with 8 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
1414 client Client
1515 instance *fargo.Instance
1616 logger log.Logger
17 quit chan bool
18 quitmtx sync.Mutex
17 quit chan struct{}
18 wg sync.WaitGroup
1919 }
2020
2121 // NewRegistrar returns an Eureka Registrar acting on behalf of the provided
3838
3939 if r.instance.LeaseInfo.RenewalIntervalInSecs > 0 {
4040 // User has opted for heartbeat functionality in Eureka.
41 r.quitmtx.Lock()
42 defer r.quitmtx.Unlock()
4341 if r.quit == nil {
44 r.quit = make(chan bool)
42 r.quit = make(chan struct{})
43 r.wg.Add(1)
4544 go r.loop()
4645 }
4746 }
5554 r.logger.Log("action", "deregister")
5655 }
5756
58 r.quitmtx.Lock()
59 defer r.quitmtx.Unlock()
6057 if r.quit != nil {
61 r.quit <- true
58 close(r.quit)
59 r.wg.Wait()
6260 r.quit = nil
6361 }
6462 }
6664 func (r *Registrar) loop() {
6765 tick := time.NewTicker(time.Duration(r.instance.LeaseInfo.RenewalIntervalInSecs) * time.Second)
6866 defer tick.Stop()
67 defer r.wg.Done()
68
6969 for {
7070 select {
7171 case <-tick.C: