internal/home: Add a status page on home
This commit is contained in:
parent
7cda92b342
commit
3d4db1744b
9 changed files with 301 additions and 118 deletions
25
pkg/timex/timex.go
Normal file
25
pkg/timex/timex.go
Normal 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
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue