fix init of timer

This commit is contained in:
Joel Wetzell
2025-11-25 06:43:06 -06:00
parent 32b6561d04
commit a807f541a1

View File

@@ -1,7 +1,6 @@
package showbridge package showbridge
import ( import (
"context"
"fmt" "fmt"
"log/slog" "log/slog"
"time" "time"
@@ -31,7 +30,7 @@ func init() {
return nil, fmt.Errorf("timer duration must be number") return nil, fmt.Errorf("timer duration must be number")
} }
return &Interval{Duration: uint32(durationNum), config: config}, nil return &Timer{Duration: uint32(durationNum), config: config}, nil
}, },
}) })
} }
@@ -48,12 +47,12 @@ func (t *Timer) RegisterRouter(router *Router) {
t.router = router t.router = router
} }
func (t *Timer) Run(ctx context.Context) error { func (t *Timer) Run() error {
t.timer = time.NewTimer(time.Millisecond * time.Duration(t.Duration)) t.timer = time.NewTimer(time.Millisecond * time.Duration(t.Duration))
defer t.timer.Stop() defer t.timer.Stop()
for { for {
select { select {
case <-ctx.Done(): case <-t.router.Context.Done():
t.timer.Stop() t.timer.Stop()
slog.Debug("router context done in module", "id", t.config.Id) slog.Debug("router context done in module", "id", t.config.Id)
return nil return nil