diff --git a/agent.go b/agent.go index 242abe9..89ea00d 100644 --- a/agent.go +++ b/agent.go @@ -37,6 +37,9 @@ type App interface { // 返回数据包时的回调函数,该函数必须是一个循环, // 且在有数据需要返回时将其放入第二个参数中的队列内 LoopWrite(context.Context, chan *anet.Msg) error + + // 服务退出信号 + OnStop() } func deferCallback(name string, fn func()) { diff --git a/agent_test.go b/agent_test.go index d827b70..c113c6e 100644 --- a/agent_test.go +++ b/agent_test.go @@ -47,6 +47,9 @@ func (a *agent) LoopWrite(context.Context, chan *anet.Msg) error { select {} } +func (a *agent) OnStop() { +} + func TestRestart(t *testing.T) { Restart(&agent{}) } diff --git a/service_fallback.go b/service_fallback.go index bac9ee1..0934995 100644 --- a/service_fallback.go +++ b/service_fallback.go @@ -38,5 +38,6 @@ func (svr *svr) Start(s service.Service) error { func (svr *svr) Stop(s service.Service) error { svr.app.stop() + svr.app.a.OnStop() return nil }