mirror of
https://github.com/jkstack/libagent.git
synced 2025-12-24 12:11:57 +08:00
增加OnStop接口
This commit is contained in:
3
agent.go
3
agent.go
@@ -37,6 +37,9 @@ type App interface {
|
||||
// 返回数据包时的回调函数,该函数必须是一个循环,
|
||||
// 且在有数据需要返回时将其放入第二个参数中的队列内
|
||||
LoopWrite(context.Context, chan *anet.Msg) error
|
||||
|
||||
// 服务退出信号
|
||||
OnStop()
|
||||
}
|
||||
|
||||
func deferCallback(name string, fn func()) {
|
||||
|
||||
@@ -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{})
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user