mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
fix init of timer
This commit is contained in:
7
timer.go
7
timer.go
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user