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

@@ -19,6 +19,7 @@ type UDPClient struct {
ctx context.Context
router route.RouteIO
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
@@ -80,7 +81,9 @@ func (uc *UDPClient) Run(ctx context.Context) error {
return errors.New("net.udp.client unable to get router from context")
}
uc.router = router
uc.ctx = ctx
moduleContext, cancel := context.WithCancel(ctx)
uc.ctx = moduleContext
uc.cancel = cancel
err := uc.SetupConn()
if err != nil {
@@ -112,3 +115,7 @@ func (uc *UDPClient) Output(ctx context.Context, payload any) error {
}
return nil
}
func (uc *UDPClient) Stop() {
uc.cancel()
}