You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cointop/cointop/refresh.go

74 lines
1.4 KiB
Go

package cointop
import (
"strings"
"time"
log "github.com/sirupsen/logrus"
)
4 years ago
// Refresh triggers a force refresh of coin data
func (ct *Cointop) Refresh() error {
log.Debug("Refresh()")
5 years ago
go func() {
<-ct.limiter
5 years ago
ct.forceRefresh <- true
5 years ago
}()
return nil
}
4 years ago
// RefreshAll triggers a force refresh of all data
func (ct *Cointop) RefreshAll() error {
log.Debug("RefreshAll()")
5 years ago
ct.refreshMux.Lock()
defer ct.refreshMux.Unlock()
ct.setRefreshStatus()
5 years ago
ct.cache.Delete("allCoinsSlugMap")
ct.cache.Delete("market")
5 years ago
go func() {
4 years ago
ct.UpdateCoins()
ct.UpdateTable()
ct.UpdateChart()
5 years ago
}()
return nil
}
4 years ago
// SetRefreshStatus sets the refresh ticker
func (ct *Cointop) setRefreshStatus() {
log.Debug("setRefreshStatus()")
go func() {
ct.loadingTicks("refreshing", 900)
ct.RowChanged()
}()
}
4 years ago
// LoadingTicks sets the loading ticking dots
func (ct *Cointop) loadingTicks(s string, t int) {
log.Debug("loadingTicks()")
interval := 150
k := 0
for i := 0; i < (t / interval); i++ {
ct.UpdateStatusbar(s + strings.Repeat(".", k))
time.Sleep(time.Duration(i*interval) * time.Millisecond)
k = k + 1
if k > 3 {
k = 0
}
}
}
5 years ago
4 years ago
// intervalFetchData does a force refresh at every interval
5 years ago
func (ct *Cointop) intervalFetchData() {
log.Debug("intervalFetchData()")
5 years ago
go func() {
for {
select {
case <-ct.forceRefresh:
4 years ago
ct.RefreshAll()
5 years ago
case <-ct.refreshTicker.C:
4 years ago
ct.RefreshAll()
5 years ago
}
}
}()
}