1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Remove the sleeps from the cryptocurrecy modules. Don't need them

This commit is contained in:
Chris Cummer 2018-06-06 15:03:59 -07:00
parent c6aee425a0
commit 4c5a203a1f
2 changed files with 19 additions and 47 deletions

View File

@ -28,7 +28,7 @@ type TextColors struct {
var ok = true
var errorText = ""
var started = false
var baseURL = "https://bittrex.com/api/v1.1/public/getmarketsummary"
// Widget define wtf widget to register widget later
@ -40,13 +40,11 @@ type Widget struct {
// NewWidget Make new instance of widget
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" Bittrex ", "bittrex", false),
summaryList: summaryList{},
}
started = false
ok = true
errorText = ""
@ -106,20 +104,9 @@ func (widget *Widget) Refresh() {
return
}
if started == false {
go func() {
for {
widget.updateSummary()
time.Sleep(time.Second * time.Duration(widget.RefreshInterval()))
}
}()
started = true
}
widget.UpdateRefreshedAt()
widget.display()
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -13,7 +13,6 @@ import (
// Config is a pointer to the global config object
var Config *config.Config
var started = false
var baseURL = "https://min-api.cryptocompare.com/data/price"
var ok = true
@ -26,7 +25,6 @@ type Widget struct {
// NewWidget Make new instance of widget
func NewWidget() *Widget {
started = false
widget := Widget{
TextWidget: wtf.NewTextWidget(" CryptoLive ", "cryptolive", false),
}
@ -36,19 +34,6 @@ func NewWidget() *Widget {
return &widget
}
func (widget *Widget) setList() {
currenciesMap, _ := Config.Map("wtf.mods.cryptolive.currencies")
widget.list = &list{}
for currency := range currenciesMap {
displayName, _ := Config.String("wtf.mods.cryptolive.currencies." + currency + ".displayName")
toList := getToList(currency)
widget.list.addItem(currency, displayName, toList)
}
}
/* -------------------- Exported Functions -------------------- */
// Refresh & update after interval time
@ -57,21 +42,8 @@ func (widget *Widget) Refresh() {
return
}
if started == false {
// this code should run once
go func() {
for {
widget.updateCurrencies()
time.Sleep(time.Duration(widget.RefreshInterval()) * time.Second)
}
}()
}
started = true
widget.UpdateRefreshedAt()
widget.View.Clear()
if !ok {
widget.View.SetText(
@ -79,12 +51,13 @@ func (widget *Widget) Refresh() {
)
return
}
display(widget)
widget.display()
}
/* -------------------- Unexported Functions -------------------- */
func display(widget *Widget) {
func (widget *Widget) display() {
str := ""
var (
fromNameColor = Config.UString("wtf.mods.cryptolive.colors.from.name", "coral")
@ -118,6 +91,18 @@ func getToList(fromName string) []*toCurrency {
return toList
}
func (widget *Widget) setList() {
currenciesMap, _ := Config.Map("wtf.mods.cryptolive.currencies")
widget.list = &list{}
for currency := range currenciesMap {
displayName, _ := Config.String("wtf.mods.cryptolive.currencies." + currency + ".displayName")
toList := getToList(currency)
widget.list.addItem(currency, displayName, toList)
}
}
func (widget *Widget) updateCurrencies() {
defer func() {
recover()
@ -149,7 +134,7 @@ func (widget *Widget) updateCurrencies() {
setPrices(&jsonResponse, fromCurrency)
}
display(widget)
widget.display()
}
func makeRequest(currency *fromCurrency) *http.Request {