mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 12:55:29 +00:00
add Stop function to module
This commit is contained in:
@@ -25,6 +25,7 @@ type MockCounterModule struct {
|
||||
outputCount int
|
||||
router route.RouteIO
|
||||
logger *slog.Logger
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
func (mcm *MockCounterModule) Id() string {
|
||||
@@ -43,7 +44,9 @@ func (mcm *MockCounterModule) Run(ctx context.Context) error {
|
||||
return fmt.Errorf("mock.counter could not get router from context")
|
||||
}
|
||||
mcm.router = router
|
||||
mcm.ctx = ctx
|
||||
moduleContext, cancel := context.WithCancel(ctx)
|
||||
mcm.ctx = moduleContext
|
||||
mcm.cancel = cancel
|
||||
<-mcm.ctx.Done()
|
||||
return nil
|
||||
}
|
||||
@@ -52,6 +55,10 @@ func (mcm *MockCounterModule) Type() string {
|
||||
return mcm.config.Type
|
||||
}
|
||||
|
||||
func (mcm *MockCounterModule) Stop() {
|
||||
mcm.cancel()
|
||||
}
|
||||
|
||||
func init() {
|
||||
module.RegisterModule(module.ModuleRegistration{
|
||||
Type: "mock.counter",
|
||||
|
||||
Reference in New Issue
Block a user