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

@@ -20,6 +20,7 @@ type UDPServer struct {
ctx context.Context
router route.RouteIO
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
@@ -88,7 +89,9 @@ func (us *UDPServer) Run(ctx context.Context) error {
return errors.New("net.udp.server unable to get router from context")
}
us.router = router
us.ctx = ctx
moduleContext, cancel := context.WithCancel(ctx)
us.ctx = moduleContext
us.cancel = cancel
listener, err := net.ListenUDP("udp", us.Addr)
if err != nil {
@@ -129,3 +132,7 @@ func (us *UDPServer) Run(ctx context.Context) error {
func (us *UDPServer) Output(ctx context.Context, payload any) error {
return errors.New("net.udp.server output is not implemented")
}
func (us *UDPServer) Stop() {
us.cancel()
}