mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
add Stop function to module
This commit is contained in:
@@ -17,6 +17,7 @@ type TimeTimer struct {
|
||||
router route.RouteIO
|
||||
timer *time.Timer
|
||||
logger *slog.Logger
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -57,7 +58,9 @@ func (t *TimeTimer) Run(ctx context.Context) error {
|
||||
return errors.New("net.tcp.client unable to get router from context")
|
||||
}
|
||||
t.router = router
|
||||
t.ctx = ctx
|
||||
moduleContext, cancel := context.WithCancel(ctx)
|
||||
t.ctx = moduleContext
|
||||
t.cancel = cancel
|
||||
|
||||
t.timer = time.NewTimer(time.Millisecond * time.Duration(t.Duration))
|
||||
defer t.timer.Stop()
|
||||
@@ -79,3 +82,7 @@ func (t *TimeTimer) Output(ctx context.Context, payload any) error {
|
||||
t.timer.Reset(time.Millisecond * time.Duration(t.Duration))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TimeTimer) Stop() {
|
||||
t.cancel()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user