internal/home: Add a status page on home

This commit is contained in:
Tom Wiesing 2022-10-06 15:32:02 +02:00
parent 7cda92b342
commit 3d4db1744b
No known key found for this signature in database
9 changed files with 301 additions and 118 deletions

25
pkg/timex/timex.go Normal file
View file

@ -0,0 +1,25 @@
package timex
import (
"context"
"time"
)
// SetInterval invokes f with the current time and then spawns a new goroutine that runs f every d, until context is closed.
func SetInterval(ctx context.Context, d time.Duration, f func(t time.Time)) {
f(time.Now())
go func() {
t := time.NewTicker(d)
defer t.Stop()
for {
select {
case tick := <-t.C:
f(tick)
case <-ctx.Done():
return
}
}
}()
}