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: determine if a store is listening to a topic
go func() {
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
for {
t := time.NewTicker(time.Second)
peerVerif:
for {
select {
case <-w.quit:
return
case <-t.C:
case <-ticker.C:
_, err := utils.SelectPeer(w.host, string(store.StoreID_v20beta3))
if err == nil {
break peerVerif
@ -578,6 +580,7 @@ func (w *WakuNode) startKeepAlive(t time.Duration) {
log.Info("Setting up ping protocol with duration of ", t)
ticker := time.NewTicker(t)
defer ticker.Stop()
go func() {
for {
@ -595,7 +598,6 @@ func (w *WakuNode) startKeepAlive(t time.Duration) {
}
}
case <-w.quit:
ticker.Stop()
return
}
}

View File

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