changes as per review

This commit is contained in:
Aarsh Shah 2020-03-25 00:35:26 +05:30
parent 82be3ee46f
commit fa575b4d32
1 changed files with 18 additions and 28 deletions

View File

@ -359,40 +359,30 @@ func (h *BasicHost) background(p goprocess.Process) {
} }
h.mx.Unlock() h.mx.Unlock()
// emit an EvtLocalAddressesUpdatedEvent & a Push Identify if our listen addresses have changed.
go func() {
for {
select {
case <-h.addrChangeChan:
h.mx.Lock()
addrs := h.Addrs()
changeEvt := makeUpdatedAddrEvent(h.lastAddrs, addrs)
if changeEvt != nil {
h.lastAddrs = addrs
}
h.mx.Unlock()
if changeEvt != nil {
err := h.emitters.evtLocalAddrsUpdated.Emit(*changeEvt)
if err != nil {
log.Warnf("error emitting event for updated addrs: %s", err)
}
h.ids.Push()
}
case <-p.Closing():
return
}
}
}()
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
h.SignalAddressChange() case <-h.addrChangeChan:
case <-p.Closing(): case <-p.Closing():
return return
} }
// emit an EvtLocalAddressesUpdatedEvent & a Push Identify if our listen addresses have changed.
h.mx.Lock()
addrs := h.Addrs()
changeEvt := makeUpdatedAddrEvent(h.lastAddrs, addrs)
if changeEvt != nil {
h.lastAddrs = addrs
}
h.mx.Unlock()
if changeEvt != nil {
err := h.emitters.evtLocalAddrsUpdated.Emit(*changeEvt)
if err != nil {
log.Warnf("error emitting event for updated addrs: %s", err)
}
h.ids.Push()
}
} }
} }