增加OnStop接口

This commit is contained in:
lwch
2023-08-07 10:56:49 +08:00
parent baa92952d8
commit 88d1ef5713
3 changed files with 7 additions and 0 deletions

View File

@@ -37,6 +37,9 @@ type App interface {
// 返回数据包时的回调函数,该函数必须是一个循环,
// 且在有数据需要返回时将其放入第二个参数中的队列内
LoopWrite(context.Context, chan *anet.Msg) error
// 服务退出信号
OnStop()
}
func deferCallback(name string, fn func()) {

View File

@@ -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{})
}

View File

@@ -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
}