fix: invalid ticker usage

This commit is contained in:
Richard Ramos 2021-11-19 19:51:18 -04:00
parent 78a0d4d74d
commit e8c08ac18b
2 changed files with 13 additions and 8 deletions

View File

@ -426,14 +426,16 @@ func (w *WakuNode) startStore() {
// TODO: extract this to a function and run it when you go offline // TODO: extract this to a function and run it when you go offline
// TODO: determine if a store is listening to a topic // TODO: determine if a store is listening to a topic
go func() { go func() {
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
for { for {
t := time.NewTicker(time.Second)
peerVerif: peerVerif:
for { for {
select { select {
case <-w.quit: case <-w.quit:
return return
case <-t.C: case <-ticker.C:
_, err := utils.SelectPeer(w.host, string(store.StoreID_v20beta3)) _, err := utils.SelectPeer(w.host, string(store.StoreID_v20beta3))
if err == nil { if err == nil {
break peerVerif break peerVerif
@ -578,6 +580,7 @@ func (w *WakuNode) startKeepAlive(t time.Duration) {
log.Info("Setting up ping protocol with duration of ", t) log.Info("Setting up ping protocol with duration of ", t)
ticker := time.NewTicker(t) ticker := time.NewTicker(t)
defer ticker.Stop()
go func() { go func() {
for { for {
@ -595,7 +598,6 @@ func (w *WakuNode) startKeepAlive(t time.Duration) {
} }
} }
case <-w.quit: case <-w.quit:
ticker.Stop()
return return
} }
} }

View File

@ -74,13 +74,16 @@ func (self *MessageQueue) cleanOlderRecords() {
func (self *MessageQueue) checkForOlderRecords(d time.Duration) { func (self *MessageQueue) checkForOlderRecords(d time.Duration) {
ticker := time.NewTicker(d) ticker := time.NewTicker(d)
defer ticker.Stop()
for {
select { select {
case <-self.quit: case <-self.quit:
return return
case <-ticker.C: case <-ticker.C:
self.cleanOlderRecords() self.cleanOlderRecords()
} }
}
} }
func (self *MessageQueue) Length() int { func (self *MessageQueue) Length() int {