feat 模块增加after start
This commit is contained in:
11
app/app.go
11
app/app.go
@@ -8,6 +8,7 @@ import (
|
||||
"git.hlsq.asia/mmorpg/service-scene/config"
|
||||
"git.hlsq.asia/mmorpg/service-scene/internal/grpc_server"
|
||||
"github.com/judwhite/go-svc"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Program struct {
|
||||
@@ -39,8 +40,16 @@ func (p *Program) Init(_ svc.Environment) error {
|
||||
}
|
||||
|
||||
func (p *Program) Start() error {
|
||||
ready := &sync.WaitGroup{}
|
||||
ready.Add(len(p.moduleList))
|
||||
for _, m := range p.moduleList {
|
||||
if err := m.Start(); err != nil {
|
||||
if err := m.Start(ready); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
ready.Wait()
|
||||
for _, m := range p.moduleList {
|
||||
if err := m.AfterStart(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
13
app/base.go
13
app/base.go
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
// ModuleBase 基础模块,或者一些零散的模块
|
||||
type ModuleBase struct {
|
||||
module.DefaultModule
|
||||
}
|
||||
|
||||
func (m *ModuleBase) Init() error {
|
||||
@@ -24,15 +25,3 @@ func (m *ModuleBase) Init() error {
|
||||
utils.InitSnowflake(int64(rand.Intn(1000)))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleBase) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleBase) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleBase) Bind(_ ...any) module.Module {
|
||||
return m
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user