feat 模块增加after start

This commit is contained in:
2026-01-20 12:11:28 +08:00
parent 5b20da3af1
commit cb37409593
4 changed files with 14 additions and 16 deletions

View File

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

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
}

2
go.mod
View File

@@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-scene
go 1.24.0
require (
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852
git.hlsq.asia/mmorpg/service-common v0.0.0-20260120040718-1edebb439c58
github.com/judwhite/go-svc v1.2.1
go.uber.org/zap v1.27.0
google.golang.org/grpc v1.77.0

4
go.sum
View File

@@ -1,7 +1,7 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852 h1:ehZ54MgGL3CO7KKDPxybFabIXxiQud1TGMcKjrSTcnw=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852/go.mod h1:Dazg+4woCv9Jk7jgT2qUSGWhZOXx/0WYfJO+FCUDyhw=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260120040718-1edebb439c58 h1:Bgn3rrISGqzyNA4ax5o4tiTy3tK3QcM/+tCr80fOBhE=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260120040718-1edebb439c58/go.mod h1:Dazg+4woCv9Jk7jgT2qUSGWhZOXx/0WYfJO+FCUDyhw=
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=