mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
reset interval on output
This commit is contained in:
@@ -10,6 +10,7 @@ type Interval struct {
|
|||||||
config ModuleConfig
|
config ModuleConfig
|
||||||
Duration uint32
|
Duration uint32
|
||||||
router *Router
|
router *Router
|
||||||
|
ticker *time.Ticker
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -48,11 +49,11 @@ func (i *Interval) RegisterRouter(router *Router) {
|
|||||||
|
|
||||||
func (i *Interval) Run() error {
|
func (i *Interval) Run() error {
|
||||||
ticker := time.NewTicker(time.Millisecond * time.Duration(i.Duration))
|
ticker := time.NewTicker(time.Millisecond * time.Duration(i.Duration))
|
||||||
|
i.ticker = ticker
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-i.router.Context.Done():
|
case <-i.router.Context.Done():
|
||||||
ticker.Stop()
|
|
||||||
slog.Debug("router context done in module", "id", i.config.Id)
|
slog.Debug("router context done in module", "id", i.config.Id)
|
||||||
return nil
|
return nil
|
||||||
case t := <-ticker.C:
|
case t := <-ticker.C:
|
||||||
@@ -65,5 +66,6 @@ func (i *Interval) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *Interval) Output(payload any) error {
|
func (i *Interval) Output(payload any) error {
|
||||||
return fmt.Errorf("interval output is not implemented")
|
i.ticker.Reset(time.Millisecond * time.Duration(i.Duration))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user