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
+5 -4
View File
@@ -63,7 +63,7 @@ func (pc *PSNClient) Start(ctx context.Context, inputHandler common.InputHandler
pc.connMu.Unlock()
buffer := make([]byte, 2048)
for {
for pc.ctx.Err() == nil {
select {
case <-pc.ctx.Done():
return nil
@@ -99,17 +99,18 @@ func (pc *PSNClient) Start(ctx context.Context, inputHandler common.InputHandler
}
}
}
<-pc.ctx.Done()
pc.logger.Debug("done")
return nil
}
func (pc *PSNClient) Stop() {
if pc.cancel != nil {
pc.cancel()
defer pc.cancel()
}
pc.connMu.Lock()
defer pc.connMu.Unlock()
if pc.conn != nil {
pc.conn.Close()
pc.conn = nil
}
pc.logger.Debug("done")
}