Browse Source

Move calculation of when refresh is to setting the value

master
Elis Hirwing 4 years ago
parent
commit
e73fe6ea40
Signed by: etu GPG Key ID: D57EFA625C9A925F
  1. 14
      src/statusscreen/SL.go

14
src/statusscreen/SL.go

@ -16,7 +16,7 @@ import (
type SL struct {
Config *Config
lastResponse SLResponse
lastRefresh int64
nextRefresh int64
}
// SLResponse is a struct to get the interesting data from API Responses
@ -56,18 +56,16 @@ func (sl *SL) GetOutput() string {
})
// Check if it's time to refresh yet
if (sl.lastRefresh + sl.Config.SL.RefreshDelay) <= time.Now().Unix() {
// If it is, refresh
if sl.nextRefresh <= time.Now().Unix() {
// If it is, refresh the data
sldata, err := sl.getTimeTable()
// If no error occured, save the latest data to the struct
if err == nil {
sl.lastResponse = sldata
sl.lastRefresh = time.Now().Unix()
}
if err != nil {
log.Fatal(err)
sl.nextRefresh = time.Now().Unix() + sl.Config.SL.RefreshDelay
} else {
// log.Fatal(err)
}
}

Loading…
Cancel
Save