mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-08-21 05:58:59 +00:00
rework module shutdown process to cancel module context in defer
This commit is contained in:
@@ -66,7 +66,7 @@ func (t *TimeTimer) Start(ctx context.Context, inputHandler common.InputHandler)
|
||||
t.cancel = cancel
|
||||
|
||||
t.timer = time.NewTimer(time.Millisecond * time.Duration(t.Duration))
|
||||
for {
|
||||
for t.ctx.Err() == nil {
|
||||
select {
|
||||
case <-t.ctx.Done():
|
||||
return nil
|
||||
@@ -76,15 +76,16 @@ func (t *TimeTimer) Start(ctx context.Context, inputHandler common.InputHandler)
|
||||
}
|
||||
}
|
||||
}
|
||||
<-t.ctx.Done()
|
||||
t.logger.Debug("done")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TimeTimer) Stop() {
|
||||
if t.cancel != nil {
|
||||
t.cancel()
|
||||
defer t.cancel()
|
||||
}
|
||||
if t.timer != nil {
|
||||
t.timer.Stop()
|
||||
t.timer = nil
|
||||
}
|
||||
t.logger.Debug("done")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user