From 06ed7d3380bf4683d6c27a8b085bf477569beb4d Mon Sep 17 00:00:00 2001 From: boyce Date: Tue, 26 Feb 2019 17:40:15 +0800 Subject: [PATCH] =?UTF-8?q?Module=E6=A8=A1=E5=9D=97=E6=96=B0=E5=A2=9EOnRun?= =?UTF-8?q?End?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/Module.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/service/Module.go b/service/Module.go index d593c1f..06c7965 100644 --- a/service/Module.go +++ b/service/Module.go @@ -16,7 +16,7 @@ const ( type IModule interface { OnInit() error //Module初始化时调用 OnRun() bool //Module运行时调用 - + OnEndRun() SetModuleId(moduleId uint32) //手动设置ModuleId GetModuleId() uint32 //获取ModuleId GetModuleById(moduleId uint32) IModule //通过ModuleId获取Module @@ -217,6 +217,9 @@ func (slf *BaseModule) OnRun() bool { return false } +func (slf *BaseModule) OnEndRun() { +} + func (slf *BaseModule) SetOwner(ownerModule IModule) { slf.ownerModule = ownerModule } @@ -260,12 +263,14 @@ func (slf *BaseModule) RunModule(module IModule) { defer slf.WaitGroup.Done() for { if atomic.LoadInt32(&slf.corouterstatus) != 0 { + slf.OnEndRun() GetLogger().Printf(LEVER_INFO, "Stopping module %T id is %d...", slf.GetSelf(), module.GetModuleId()) break } select { case <-slf.ExitChan: + slf.OnEndRun() GetLogger().Printf(LEVER_INFO, "Stopping module %T...", slf.GetSelf()) fmt.Println("Stopping module %T...", slf.GetSelf()) return @@ -273,6 +278,7 @@ func (slf *BaseModule) RunModule(module IModule) { } if module.OnRun() == false { + slf.OnEndRun() return } }