Jakub Sokołowski 923ae10e4a use the time.After in fetching loop select case
Signed-off-by: Jakub Sokołowski <jakub@status.im>
2019-07-01 13:07:20 -04:00

20 lines
312 B
Go

package main
import (
"time"
)
func FetchLoop(state *State, interval int) {
// Get the first peers fetch going sooner
state.Fetch()
// Then fetch every `interval` seconds
for {
select {
case <-threadDone:
return
case <-time.After(time.Duration(interval) * time.Second):
state.Fetch()
}
}
}