diff --git a/service/Service.go b/service/Service.go index b73fcbd..760000c 100644 --- a/service/Service.go +++ b/service/Service.go @@ -20,6 +20,7 @@ type MethodInfo struct { type IModule interface { SetModuleType(moduleType uint32) GetModuleType() uint32 + DynamicRun(module IModule) RunModule(module IModule, exit chan bool, pwaitGroup *sync.WaitGroup) error InitModule(module IModule) error OnInit() error @@ -79,6 +80,9 @@ type BaseModule struct { ownerService IService tickTime int64 + + exit chan bool + pwaitGroup *sync.WaitGroup } func (slf *BaseService) GetServiceId() int { @@ -217,7 +221,14 @@ func (slf *BaseModule) InitModule(module IModule) error { return nil } +func (slf *BaseModule) DynamicRun(module IModule) { + module.InitModule(module) + module.RunModule(module, slf.exit, slf.pwaitGroup) +} + func (slf *BaseModule) RunModule(module IModule, exit chan bool, pwaitGroup *sync.WaitGroup) error { + slf.exit = exit + slf.pwaitGroup = pwaitGroup //运行所有子模块 for _, subModule := range slf.mapModule { go subModule.RunModule(subModule, exit, pwaitGroup)