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:
@@ -24,6 +24,7 @@ type SerialClient struct {
|
||||
Mode *serial.Mode
|
||||
port serial.Port
|
||||
logger *slog.Logger
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -108,7 +109,9 @@ func (sc *SerialClient) Run(ctx context.Context) error {
|
||||
}
|
||||
|
||||
sc.router = router
|
||||
sc.ctx = ctx
|
||||
moduleContext, cancel := context.WithCancel(ctx)
|
||||
sc.ctx = moduleContext
|
||||
sc.cancel = cancel
|
||||
|
||||
// TODO(jwetzell): shutdown with router.Context properly
|
||||
go func() {
|
||||
@@ -180,3 +183,7 @@ func (sc *SerialClient) Output(ctx context.Context, payload any) error {
|
||||
_, err := sc.port.Write(sc.Framer.Encode(payloadBytes))
|
||||
return err
|
||||
}
|
||||
|
||||
func (sc *SerialClient) Stop() {
|
||||
sc.cancel()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user