add Stop function to module

This commit is contained in:
Joel Wetzell
2026-02-07 09:53:38 -06:00
parent 8f5091cf9b
commit 33ecc94097
19 changed files with 156 additions and 18 deletions

View File

@@ -21,6 +21,7 @@ type TCPClient struct {
router route.RouteIO
Addr *net.TCPAddr
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
@@ -94,7 +95,9 @@ func (tc *TCPClient) Run(ctx context.Context) error {
return errors.New("net.tcp.client unable to get router from context")
}
tc.router = router
tc.ctx = ctx
moduleContext, cancel := context.WithCancel(ctx)
tc.ctx = moduleContext
tc.cancel = cancel
// TODO(jwetzell): shutdown with router.Context properly
go func() {
@@ -176,3 +179,7 @@ func (tc *TCPClient) Output(ctx context.Context, payload any) error {
_, err := tc.conn.Write(tc.framer.Encode(payloadBytes))
return err
}
func (tc *TCPClient) Stop() {
tc.cancel()
}