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 NATSClient struct {
Subject string
client *nats.Conn
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
@@ -71,7 +72,9 @@ func (nc *NATSClient) Run(ctx context.Context) error {
}
nc.router = router
nc.ctx = ctx
moduleContext, cancel := context.WithCancel(ctx)
nc.ctx = moduleContext
nc.cancel = cancel
client, err := nats.Connect(nc.URL, nats.RetryOnFailedConnect(true))
@@ -121,3 +124,7 @@ func (nc *NATSClient) Output(ctx context.Context, payload any) error {
return err
}
func (nc *NATSClient) Stop() {
nc.cancel()
}