Use tickers instead of time.Sleep(), simplify main loop condition

This commit is contained in:
eleksir
2025-04-07 20:41:01 +03:00
parent 44dbaee87a
commit 4fd0815c1d
8 changed files with 439 additions and 388 deletions

View File

@@ -9,7 +9,19 @@ import (
// UpdateLaStats вытаскивает показание LA за последнюю минуту.
func (c *MyConfig) UpdateLaStats() {
for {
var (
InitialDelay = 100 * time.Millisecond
LoopIterationDelay = 3 * time.Second
Delay = InitialDelay
ticker = time.NewTicker(Delay)
)
for range ticker.C {
if Delay == InitialDelay {
Delay = LoopIterationDelay
ticker.Reset(Delay)
}
l, _ := load.Avg()
lav := fmt.Sprintf("%.2f", l.Load1)
@@ -18,7 +30,5 @@ func (c *MyConfig) UpdateLaStats() {
c.Values.La = lav
c.Channels.UpdateReady <- true
}
time.Sleep(3 * time.Second)
}
}