Skip to content

Commit

Permalink
整理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
pangdogs committed Jan 18, 2025
1 parent 45757d5 commit d08ce37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions runtime_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"git.golaxy.org/framework/addins/rpcstack"
etcdv3 "go.etcd.io/etcd/client/v3"
"go.uber.org/zap"
"sync"
)

type _RuntimeSettings struct {
Expand All @@ -55,17 +56,20 @@ type iRuntimeGeneric interface {

// RuntimeGeneric 运行时泛化类型
type RuntimeGeneric struct {
once sync.Once
svcInst IServiceInstance
instance any
handleEntityManagerAddEntity runtime.EventEntityManagerAddEntityHandler
handleEntityManagerEntityAddComponents runtime.EventEntityManagerEntityAddComponentsHandler
}

func (r *RuntimeGeneric) init(svcCtx service.Context, instance any) {
r.svcInst = reinterpret.Cast[IServiceInstance](svcCtx)
r.instance = instance
r.handleEntityManagerAddEntity = runtime.HandleEventEntityManagerAddEntity(r.onEntityManagerAddEntity)
r.handleEntityManagerEntityAddComponents = runtime.HandleEventEntityManagerEntityAddComponents(r.onEntityManagerEntityAddComponents)
r.once.Do(func() {
r.svcInst = reinterpret.Cast[IServiceInstance](svcCtx)
r.instance = instance
r.handleEntityManagerAddEntity = runtime.HandleEventEntityManagerAddEntity(r.onEntityManagerAddEntity)
r.handleEntityManagerEntityAddComponents = runtime.HandleEventEntityManagerEntityAddComponents(r.onEntityManagerEntityAddComponents)
})
}

func (r *RuntimeGeneric) generate(settings _RuntimeSettings) core.Runtime {
Expand Down
9 changes: 6 additions & 3 deletions service_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ type iServiceGeneric interface {

// ServiceGeneric 服务泛化类型
type ServiceGeneric struct {
once sync.Once
startupConf *viper.Viper
name string
instance any
}

func (s *ServiceGeneric) init(startupConf *viper.Viper, name string, instance any) {
s.startupConf = startupConf
s.name = name
s.instance = instance
s.once.Do(func() {
s.startupConf = startupConf
s.name = name
s.instance = instance
})
}

func (s *ServiceGeneric) generate(ctx context.Context, no int) core.Service {
Expand Down
3 changes: 2 additions & 1 deletion service_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type IServiceInstance interface {
// ServiceInstance 服务实例
type ServiceInstance struct {
service.ContextBehavior
runtimeGeneric RuntimeGeneric
}

// GetConf 获取配置插件
Expand Down Expand Up @@ -141,7 +142,7 @@ func (inst *ServiceInstance) GetMemKV() *sync.Map {

// CreateRuntime 创建运行时
func (inst *ServiceInstance) CreateRuntime() RuntimeCreator {
return CreateRuntime(service.UnsafeContext(inst).GetOptions().InstanceFace.Iface)
return CreateRuntime(service.UnsafeContext(inst).GetOptions().InstanceFace.Iface).Setup(&inst.runtimeGeneric)
}

// CreateEntityPT 创建实体原型
Expand Down

0 comments on commit d08ce37

Please sign in to comment.