Browse Source

Get weather in a goroutine as well

master
Elis Hirwing 2 years ago
parent
commit
23d000aac0
Signed by: etu <elis@hirwing.se> GPG Key ID: D57EFA625C9A925F
1 changed files with 13 additions and 8 deletions
  1. +13
    -8
      src/statusscreen/Weather.go

+ 13
- 8
src/statusscreen/Weather.go View File

@@ -17,14 +17,8 @@ type Weather struct {
// GetOutput returns a rendered result of this module
func (weather *Weather) GetOutput() []string {
if weather.nextRefresh <= time.Now().Unix() {
myWeather, err := weather.getWeather()

if err == nil {
weather.lastResponse = myWeather
weather.nextRefresh = time.Now().Unix() + weather.Config.Weather.RefreshDelay
} else {
// log.Fatal(err)
}
weather.nextRefresh += 10
go weather.getData()
}

parts := strings.Split(weather.lastResponse, "\n")
@@ -36,6 +30,17 @@ func (weather *Weather) GetOutput() []string {
return []string{}
}

func (weather *Weather) getData() {
myWeather, err := weather.getWeather()

if err == nil {
weather.lastResponse = myWeather
weather.nextRefresh = time.Now().Unix() + weather.Config.Weather.RefreshDelay
} else {
// log.Fatal(err)
}
}

func (weather *Weather) getWeather() (string, error) {
// Set up http client to fetch weather
client := &http.Client{


Loading…
Cancel
Save