rework module shutdown process to cancel module context in defer

This commit is contained in:
Joel Wetzell
2026-05-27 20:50:33 -05:00
parent 52ca801fbd
commit 0b494fce91
21 changed files with 197 additions and 216 deletions
+3 -3
View File
@@ -159,6 +159,8 @@ func (sc *SerialClient) Start(ctx context.Context, inputHandler common.InputHand
}
}
}
<-sc.ctx.Done()
sc.logger.Debug("done")
return nil
}
@@ -176,13 +178,11 @@ func (sc *SerialClient) Output(ctx context.Context, payload any) error {
func (sc *SerialClient) Stop() {
if sc.cancel != nil {
sc.cancel()
defer sc.cancel()
}
sc.portMu.Lock()
defer sc.portMu.Unlock()
if sc.port != nil {
sc.port.Close()
sc.port = nil
}
sc.logger.Debug("done")
}