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

@@ -7,7 +7,19 @@ import (
// UpdateClock get and updates (on i3bar) info about system clock.
func (c *MyConfig) UpdateClock() {
for {
var (
InitialDelay = 100 * time.Millisecond
LoopIterationDelay = 1 * time.Second
Delay = InitialDelay
ticker = time.NewTicker(Delay)
)
for range ticker.C {
if Delay == InitialDelay {
Delay = LoopIterationDelay
ticker.Reset(Delay)
}
currentTime := time.Now()
hours, minutes, _ := currentTime.Clock()
year, month, day := currentTime.Date()
@@ -21,7 +33,5 @@ func (c *MyConfig) UpdateClock() {
c.Values.ClockTime = myclock
c.Channels.UpdateReady <- true
}
time.Sleep(1 * time.Second)
}
}