feat 模块增加after start

This commit is contained in:
2026-01-20 12:11:29 +08:00
parent 81bae2992d
commit f1f8e162e0
4 changed files with 14 additions and 16 deletions

View File

@@ -8,6 +8,7 @@ import (
"git.hlsq.asia/mmorpg/service-user/config"
"git.hlsq.asia/mmorpg/service-user/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
}
}

View File

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