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:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user