Documentation
¶
Overview ¶
Package core 提供框架的公共入口与跨包编排能力。
Package core 把 service、runtime、ec、event 和 extension 等子包串联成完整的 运行模型。
典型流程如下:
- 用 service.NewContext 创建服务上下文。
- 用 BuildEntityPT 或 service.Context.EntityLib() 声明实体原型。
- 用 runtime.NewContext 创建运行时上下文。
- 用 NewService 和 NewRuntime 启动服务与运行时。
- 用 BuildEntity 在运行时中创建实体,并让组件生命周期自动推进。
此外,根包还提供:
- 实体、组件、插件的生命周期接口;
- Submit/Post Actor 邮箱调度,以及保留 Delegate/DelegateVoid 的对应变体;
- Scope/Spawn 结构化后台任务与 ContinueOn Runtime 续体;
- After、Every 等定时和连续流入口;
- Service、Runtime、Frame 与 TaskQueue 的选项构造器;
- 面向框架集成与高级扩展场景的 unsafe 辅助入口。
业务模型与底层数据结构分别位于 ec、runtime、service、event、extension、 define 与 utils 子包中。
Index ¶
- Variables
- func After(ctx context.Context, dur time.Duration) async.Future
- func At(ctx context.Context, at time.Time) async.Future
- func ContinueOn(provider corectx.ConcurrentContextProvider, future async.Future, ...) async.Future
- func ContinueOnDelegate(provider corectx.ConcurrentContextProvider, future async.Future, ...) async.Future
- func ContinueOnDelegateVoid(provider corectx.ConcurrentContextProvider, future async.Future, ...) async.Future
- func ContinueOnVoid(provider corectx.ConcurrentContextProvider, future async.Future, ...) async.Future
- func Every(ctx context.Context, dur time.Duration) async.Stream
- func FromChan[T any](ctx context.Context, ch <-chan T) async.Stream
- func Post(provider corectx.ConcurrentContextProvider, ...) error
- func PostDelegate(provider corectx.ConcurrentContextProvider, ...) error
- func Spawn(provider corectx.AsyncScopeProvider, ...) async.Future
- func SpawnVoid(provider corectx.AsyncScopeProvider, ...) async.Future
- func Submit(provider corectx.ConcurrentContextProvider, ...) async.Future
- func SubmitDelegate(provider corectx.ConcurrentContextProvider, ...) async.Future
- func SubmitDelegateVoid(provider corectx.ConcurrentContextProvider, ...) async.Future
- func SubmitVoid(provider corectx.ConcurrentContextProvider, ...) async.Future
- func UnsafeRuntime(runtime Runtime) _UnsafeRuntimedeprecated
- func UnsafeService(service Service) _UnsafeServicedeprecated
- type CustomGC
- type EntityCreator
- func (c *EntityCreator) AssignMeta(m meta.Meta) *EntityCreator
- func (c *EntityCreator) MergeMeta(dict map[string]any) *EntityCreator
- func (c *EntityCreator) MergeMetaIfAbsent(dict map[string]any) *EntityCreator
- func (c *EntityCreator) New() (ec.Entity, error)
- func (c *EntityCreator) SetComponentAwakeOnFirstTouch(b bool) *EntityCreator
- func (c *EntityCreator) SetComponentUniqueID(b bool) *EntityCreator
- func (c *EntityCreator) SetInstance(instance ec.Entity) *EntityCreator
- func (c *EntityCreator) SetInstanceFace(face iface.Face[ec.Entity]) *EntityCreator
- func (c *EntityCreator) SetMeta(dict map[string]any) *EntityCreator
- func (c *EntityCreator) SetPersistId(id uid.Id) *EntityCreator
- func (c *EntityCreator) SetScope(scope ec.Scope) *EntityCreator
- type EntityPTCreator
- func (c *EntityPTCreator) AddComponent(comp any, name ...string) *EntityPTCreator
- func (c *EntityPTCreator) AssignMeta(m meta.Meta) *EntityPTCreator
- func (c *EntityPTCreator) Declare()
- func (c *EntityPTCreator) MergeMeta(dict map[string]any) *EntityPTCreator
- func (c *EntityPTCreator) MergeMetaIfAbsent(dict map[string]any) *EntityPTCreator
- func (c *EntityPTCreator) SetComponentAwakeOnFirstTouch(b bool) *EntityPTCreator
- func (c *EntityPTCreator) SetComponentUniqueID(b bool) *EntityPTCreator
- func (c *EntityPTCreator) SetInstance(instance any) *EntityPTCreator
- func (c *EntityPTCreator) SetMeta(dict map[string]any) *EntityPTCreator
- func (c *EntityPTCreator) SetScope(scope ec.Scope) *EntityPTCreator
- type FrameOptions
- type LifecycleAddInInit
- type LifecycleAddInOnRuntimeRunningEvent
- type LifecycleAddInShut
- type LifecycleComponentAwake
- type LifecycleComponentDispose
- type LifecycleComponentLateUpdate
- type LifecycleComponentOnDisable
- type LifecycleComponentOnEnable
- type LifecycleComponentShut
- type LifecycleComponentStart
- type LifecycleComponentUpdate
- type LifecycleEntityAwake
- type LifecycleEntityDispose
- type LifecycleEntityLateUpdate
- type LifecycleEntityShut
- type LifecycleEntityStart
- type LifecycleEntityUpdate
- type LifecycleRuntimeAddInInit
- type LifecycleRuntimeAddInShut
- type LifecycleServiceAddInInit
- type LifecycleServiceAddInShut
- type Runtime
- type RuntimeBehavior
- func (rt *RuntimeBehavior) ConcurrentContextCache() iface.Cache
- func (rt *RuntimeBehavior) CurrentContextCache() iface.Cache
- func (rt *RuntimeBehavior) InstanceFaceCache() iface.Cache
- func (rt *RuntimeBehavior) PushPost(fun generic.ActionVar1[runtime.Context, any], args ...any) error
- func (rt *RuntimeBehavior) PushPostDelegate(fun generic.DelegateVoidVar1[runtime.Context, any], args ...any) error
- func (rt *RuntimeBehavior) PushSubmit(fun generic.FuncVar1[runtime.Context, any, async.Result], args ...any) async.Future
- func (rt *RuntimeBehavior) PushSubmitDelegate(fun generic.DelegateVar1[runtime.Context, any, async.Result], args ...any) async.Future
- func (rt *RuntimeBehavior) PushSubmitDelegateVoid(fun generic.DelegateVoidVar1[runtime.Context, any], args ...any) async.Future
- func (rt *RuntimeBehavior) PushSubmitVoid(fun generic.ActionVar1[runtime.Context, any], args ...any) async.Future
- func (rt *RuntimeBehavior) Run() async.Signal
- func (rt *RuntimeBehavior) Stats() RuntimeStats
- func (rt *RuntimeBehavior) Terminate() async.Signal
- func (rt *RuntimeBehavior) Terminated() async.Signal
- type RuntimeHealthStats
- type RuntimeOptions
- type RuntimeStats
- type RuntimeTaskStats
- type Service
- type ServiceBehavior
- func (svc *ServiceBehavior) Context() service.Context
- func (svc *ServiceBehavior) InstanceFaceCache() iface.Cache
- func (svc *ServiceBehavior) Run() async.Signal
- func (svc *ServiceBehavior) Stats() ServiceStats
- func (svc *ServiceBehavior) Terminate() async.Signal
- func (svc *ServiceBehavior) Terminated() async.Signal
- type ServiceOptions
- type ServiceStats
- type TaskQueueOptions
- type TaskQueueStats
- type TaskType
Constants ¶
This section is empty.
Variables ¶
var ( ErrCore = exception.ErrCore // 内核错误。 ErrPanicked = exception.ErrPanicked // panic 错误。 ErrArgs = exception.ErrArgs // 参数错误。 ErrRuntime = fmt.Errorf("%w: runtime", ErrCore) // 运行时错误。 ErrService = fmt.Errorf("%w: service", ErrCore) // 服务错误。 )
var ( ErrTaskQueueClosed = fmt.Errorf("%w: task queue is closed", ErrRuntime) // 任务队列已关闭。 ErrTaskQueueFull = fmt.Errorf("%w: task queue is full", ErrRuntime) // 任务队列已满。 )
var With _Option
With 汇总 Runtime、Frame、TaskQueue 与 Service 的选项构造器。
Functions ¶
func ContinueOn ¶ added in v0.4.27
func ContinueOn( provider corectx.ConcurrentContextProvider, future async.Future, fun generic.FuncVar2[runtime.Context, async.Result, any, async.Result], args ...any, ) async.Future
ContinueOn 在 future 完成后,把 fun 作为新任务投递到 provider 所属 Runtime。
它在订阅、入队和执行前检查异步 Scope;队列关闭、容量不足、Scope 关闭和回调 panic 都通过返回 Future 报告。回调始终在 Runtime goroutine 中串行执行。
func ContinueOnDelegate ¶ added in v0.4.27
func ContinueOnDelegate( provider corectx.ConcurrentContextProvider, future async.Future, fun generic.DelegateVar2[runtime.Context, async.Result, any, async.Result], args ...any, ) async.Future
ContinueOnDelegate 是 ContinueOn 的 Delegate 版本。
func ContinueOnDelegateVoid ¶ added in v0.4.27
func ContinueOnDelegateVoid( provider corectx.ConcurrentContextProvider, future async.Future, fun generic.DelegateVoidVar2[runtime.Context, async.Result, any], args ...any, ) async.Future
ContinueOnDelegateVoid 是 ContinueOnVoid 的 DelegateVoid 版本。
func ContinueOnVoid ¶ added in v0.4.27
func ContinueOnVoid( provider corectx.ConcurrentContextProvider, future async.Future, fun generic.ActionVar2[runtime.Context, async.Result, any], args ...any, ) async.Future
ContinueOnVoid 在 Runtime 中执行无业务返回值续体,并返回可等待错误的 Future。
func Post ¶ added in v0.4.27
func Post(provider corectx.ConcurrentContextProvider, fun generic.ActionVar1[runtime.Context, any], args ...any) error
Post 将无返回值函数投递到 provider 所属 Runtime,不创建 Future。 仅返回队列关闭、容量不足等同步入队错误。
func PostDelegate ¶ added in v0.4.27
func PostDelegate(provider corectx.ConcurrentContextProvider, fun generic.DelegateVoidVar1[runtime.Context, any], args ...any) error
PostDelegate 将无返回值委托投递到 provider 所属 Runtime,不创建 Future。
func Spawn ¶ added in v0.4.27
func Spawn(provider corectx.AsyncScopeProvider, fun generic.FuncVar1[context.Context, any, async.Result], args ...any) async.Future
Spawn 在 provider 的生命周期 Scope 中启动后台 goroutine。 fun 不得直接访问 Runtime 局部状态。
func SpawnVoid ¶ added in v0.4.27
func SpawnVoid(provider corectx.AsyncScopeProvider, fun generic.ActionVar1[context.Context, any], args ...any) async.Future
SpawnVoid 在 provider 的生命周期 Scope 中启动无业务返回值的后台 goroutine。
func Submit ¶ added in v0.4.27
func Submit(provider corectx.ConcurrentContextProvider, fun generic.FuncVar1[runtime.Context, any, async.Result], args ...any) async.Future
Submit 将有返回值函数投递到 provider 所属 Runtime,并返回执行结果 Future。
func SubmitDelegate ¶ added in v0.4.27
func SubmitDelegate(provider corectx.ConcurrentContextProvider, fun generic.DelegateVar1[runtime.Context, any, async.Result], args ...any) async.Future
SubmitDelegate 将有返回值委托投递到 provider 所属 Runtime。
func SubmitDelegateVoid ¶ added in v0.4.27
func SubmitDelegateVoid(provider corectx.ConcurrentContextProvider, fun generic.DelegateVoidVar1[runtime.Context, any], args ...any) async.Future
SubmitDelegateVoid 将无业务返回值委托投递到 provider 所属 Runtime。
func SubmitVoid ¶ added in v0.4.27
func SubmitVoid(provider corectx.ConcurrentContextProvider, fun generic.ActionVar1[runtime.Context, any], args ...any) async.Future
SubmitVoid 将无业务返回值函数投递到 provider 所属 Runtime,并返回可等待错误的 Future。
func UnsafeRuntime
deprecated
func UnsafeRuntime(runtime Runtime) _UnsafeRuntime
Deprecated: UnsafeRuntime 暴露运行时内部能力,仅供框架集成代码使用。
func UnsafeService
deprecated
func UnsafeService(service Service) _UnsafeService
Deprecated: UnsafeService 暴露服务内部能力,仅供框架集成代码使用。
Types ¶
type EntityCreator ¶
type EntityCreator struct {
// contains filtered or unexported fields
}
EntityCreator 基于已声明原型配置并创建实体。
func BuildEntity ¶ added in v0.3.92
func BuildEntity(provider corectx.CurrentContextProvider, prototype string) *EntityCreator
BuildEntity 创建绑定到 provider 当前运行时的实体构建器。 prototype 必须已经在所属服务的实体原型库中声明。
func (*EntityCreator) AssignMeta ¶ added in v0.4.9
func (c *EntityCreator) AssignMeta(m meta.Meta) *EntityCreator
AssignMeta 直接采用 m 作为待创建实体的元数据。
func (*EntityCreator) MergeMeta ¶ added in v0.4.9
func (c *EntityCreator) MergeMeta(dict map[string]any) *EntityCreator
MergeMeta 合并元数据;同名键会被覆盖。
func (*EntityCreator) MergeMetaIfAbsent ¶ added in v0.4.9
func (c *EntityCreator) MergeMetaIfAbsent(dict map[string]any) *EntityCreator
MergeMetaIfAbsent 合并元数据;已有的同名键保持不变。
func (*EntityCreator) New ¶ added in v0.3.92
func (c *EntityCreator) New() (ec.Entity, error)
New 根据原型构造实体,并将其加入绑定运行时的实体管理器。
func (*EntityCreator) SetComponentAwakeOnFirstTouch ¶ added in v0.3.92
func (c *EntityCreator) SetComponentAwakeOnFirstTouch(b bool) *EntityCreator
SetComponentAwakeOnFirstTouch 设置组件是否延迟到首次访问时进入 Awakened 状态。
func (*EntityCreator) SetComponentUniqueID ¶ added in v0.3.92
func (c *EntityCreator) SetComponentUniqueID(b bool) *EntityCreator
SetComponentUniqueID 设置是否为每个组件分配独立 ID。
func (*EntityCreator) SetInstance ¶ added in v0.3.92
func (c *EntityCreator) SetInstance(instance ec.Entity) *EntityCreator
SetInstance 设置用于扩展实体能力的自定义实例。
func (*EntityCreator) SetInstanceFace ¶ added in v0.3.92
func (c *EntityCreator) SetInstanceFace(face iface.Face[ec.Entity]) *EntityCreator
SetInstanceFace 设置用于扩展实体能力的自定义实例及其接口缓存。
func (*EntityCreator) SetMeta ¶ added in v0.3.92
func (c *EntityCreator) SetMeta(dict map[string]any) *EntityCreator
SetMeta 用 dict 替换待创建实体的元数据。
func (*EntityCreator) SetPersistId ¶ added in v0.3.92
func (c *EntityCreator) SetPersistId(id uid.Id) *EntityCreator
SetPersistId 设置实体的持久化 ID。
func (*EntityCreator) SetScope ¶ added in v0.3.92
func (c *EntityCreator) SetScope(scope ec.Scope) *EntityCreator
SetScope 覆盖原型定义的实体可访问作用域。
type EntityPTCreator ¶ added in v0.2.39
type EntityPTCreator struct {
// contains filtered or unexported fields
}
EntityPTCreator 以链式方式配置并声明实体原型。
func BuildEntityPT ¶ added in v0.3.92
func BuildEntityPT(svcCtx service.Context, prototype string) *EntityPTCreator
BuildEntityPT 创建绑定到 svcCtx 实体原型库的构建器。
func (*EntityPTCreator) AddComponent ¶ added in v0.2.39
func (c *EntityPTCreator) AddComponent(comp any, name ...string) *EntityPTCreator
AddComponent 向原型追加一个内建组件。 comp 可以是组件实例或 ComponentDescriptor;未指定名称时使用组件类型名。
func (*EntityPTCreator) AssignMeta ¶ added in v0.4.25
func (c *EntityPTCreator) AssignMeta(m meta.Meta) *EntityPTCreator
AssignMeta 直接采用 m 作为原型元数据。
func (*EntityPTCreator) Declare ¶ added in v0.2.39
func (c *EntityPTCreator) Declare()
Declare 将构建结果注册到服务的实体原型库。
func (*EntityPTCreator) MergeMeta ¶ added in v0.4.25
func (c *EntityPTCreator) MergeMeta(dict map[string]any) *EntityPTCreator
MergeMeta 合并原型元数据;同名键会被覆盖。
func (*EntityPTCreator) MergeMetaIfAbsent ¶ added in v0.4.25
func (c *EntityPTCreator) MergeMetaIfAbsent(dict map[string]any) *EntityPTCreator
MergeMetaIfAbsent 合并原型元数据;已有的同名键保持不变。
func (*EntityPTCreator) SetComponentAwakeOnFirstTouch ¶ added in v0.3.92
func (c *EntityPTCreator) SetComponentAwakeOnFirstTouch(b bool) *EntityPTCreator
SetComponentAwakeOnFirstTouch 设置组件是否延迟到首次访问时进入 Awakened 状态。
func (*EntityPTCreator) SetComponentUniqueID ¶ added in v0.3.92
func (c *EntityPTCreator) SetComponentUniqueID(b bool) *EntityPTCreator
SetComponentUniqueID 设置是否为每个组件分配独立 ID。
func (*EntityPTCreator) SetInstance ¶ added in v0.3.92
func (c *EntityPTCreator) SetInstance(instance any) *EntityPTCreator
SetInstance 设置该原型用于构造自定义实体的实例或反射类型。
func (*EntityPTCreator) SetMeta ¶ added in v0.4.25
func (c *EntityPTCreator) SetMeta(dict map[string]any) *EntityPTCreator
SetMeta 用 dict 替换原型元数据。
func (*EntityPTCreator) SetScope ¶ added in v0.3.92
func (c *EntityPTCreator) SetScope(scope ec.Scope) *EntityPTCreator
SetScope 设置由该原型创建的实体可访问作用域。
type FrameOptions ¶ added in v0.4.25
type FrameOptions struct {
Enabled bool // 是否启用帧循环。
TargetFPS float64 // 目标 FPS;设置时会四舍五入为整数值。
TotalFrames int64 // 最大运行帧数;0 表示不限制。
}
FrameOptions 定义运行时帧循环的选项。
type LifecycleAddInInit ¶ added in v0.3.66
LifecycleAddInInit 在插件激活时调用。 服务插件的 rtCtx 为 nil;运行时插件会同时收到所属服务和运行时上下文。
type LifecycleAddInOnRuntimeRunningEvent ¶ added in v0.4.25
type LifecycleAddInOnRuntimeRunningEvent = runtime.EventContextRunningEvent
LifecycleAddInOnRuntimeRunningEvent 使运行时插件接收激活后的运行事件。
type LifecycleAddInShut ¶ added in v0.3.66
LifecycleAddInShut 在插件停用时调用。 服务插件的 rtCtx 为 nil;运行时插件会同时收到所属服务和运行时上下文。
type LifecycleComponentAwake ¶
type LifecycleComponentAwake interface {
Awake()
}
LifecycleComponentAwake 在组件进入 Awakened 状态时调用,每个组件最多调用一次。
type LifecycleComponentDispose ¶
type LifecycleComponentDispose interface {
Dispose()
}
LifecycleComponentDispose 在已唤醒的组件进入 Dead 状态时调用,与 LifecycleComponentAwake 成对。
type LifecycleComponentLateUpdate ¶
type LifecycleComponentLateUpdate = eventLateUpdate
LifecycleComponentLateUpdate 在每帧普通更新结束后接收后置更新。
type LifecycleComponentOnDisable ¶ added in v0.3.80
type LifecycleComponentOnDisable interface {
OnDisable()
}
LifecycleComponentOnDisable 在组件被禁用时调用,与 LifecycleComponentOnEnable 成对。
type LifecycleComponentOnEnable ¶ added in v0.3.80
type LifecycleComponentOnEnable interface {
OnEnable()
}
LifecycleComponentOnEnable 在组件被启用时调用,可随启用状态切换而多次调用。
type LifecycleComponentShut ¶
type LifecycleComponentShut interface {
Shut()
}
LifecycleComponentShut 在已开始的组件进入 Shutting 状态时调用,与 LifecycleComponentStart 成对。
type LifecycleComponentStart ¶
type LifecycleComponentStart interface {
Start()
}
LifecycleComponentStart 在已启用组件进入 Starting 状态时调用,每个组件最多调用一次。
type LifecycleComponentUpdate ¶
type LifecycleComponentUpdate = eventUpdate
LifecycleComponentUpdate 在启用帧循环且组件处于 Alive 状态时接收每帧更新。
type LifecycleEntityAwake ¶
type LifecycleEntityAwake interface {
Awake()
}
LifecycleEntityAwake 在实体进入 Awakened 状态时调用,每个实体最多调用一次。
type LifecycleEntityDispose ¶
type LifecycleEntityDispose interface {
Dispose()
}
LifecycleEntityDispose 在已唤醒的实体进入 Dead 状态时调用,与 LifecycleEntityAwake 成对。
type LifecycleEntityLateUpdate ¶
type LifecycleEntityLateUpdate = eventLateUpdate
LifecycleEntityLateUpdate 在每帧普通更新结束后接收后置更新。
type LifecycleEntityShut ¶
type LifecycleEntityShut interface {
Shut()
}
LifecycleEntityShut 在已开始的实体进入 Shutting 状态时调用,与 LifecycleEntityStart 成对。
type LifecycleEntityStart ¶
type LifecycleEntityStart interface {
Start()
}
LifecycleEntityStart 在实体进入 Starting 状态时调用,每个实体最多调用一次。
type LifecycleEntityUpdate ¶
type LifecycleEntityUpdate = eventUpdate
LifecycleEntityUpdate 在启用帧循环且实体处于 Alive 状态时接收每帧更新。
type LifecycleRuntimeAddInInit ¶ added in v0.4.2
LifecycleRuntimeAddInInit 在运行时插件激活时调用。
type LifecycleRuntimeAddInShut ¶ added in v0.4.2
LifecycleRuntimeAddInShut 在运行时插件停用时调用。
type LifecycleServiceAddInInit ¶ added in v0.4.2
LifecycleServiceAddInInit 在服务插件激活时调用。
type LifecycleServiceAddInShut ¶ added in v0.4.2
LifecycleServiceAddInShut 在服务插件停用时调用。
type Runtime ¶
type Runtime interface {
corectx.CurrentContextProvider
corectx.ConcurrentContextProvider
reinterpret.InstanceProvider
runtime.Callee
// contains filtered or unexported methods
}
Runtime 驱动单个 Actor 风格运行时的任务队列、实体生命周期和可选帧循环。
func NewRuntime ¶
NewRuntime 创建运行时并将 rtCtx 绑定到该运行时。 同一个运行时上下文只能绑定一次;创建期间会同步触发 RunningEvent_Birth。
func UnsafeNewRuntime
deprecated
func UnsafeNewRuntime(rtCtx runtime.Context, options RuntimeOptions) Runtime
Deprecated: UnsafeNewRuntime 仅供框架内部使用,请改用 NewRuntime。
type RuntimeBehavior ¶
type RuntimeBehavior struct {
// contains filtered or unexported fields
}
RuntimeBehavior 提供 Runtime 的默认实现。 扩展运行时类型时应匿名嵌入该类型,并通过 InstanceFace 传入扩展实例。
func (*RuntimeBehavior) ConcurrentContextCache ¶ added in v0.4.27
func (rt *RuntimeBehavior) ConcurrentContextCache() iface.Cache
ConcurrentContextCache 返回可跨 goroutine 使用的上下文接口缓存。
func (*RuntimeBehavior) CurrentContextCache ¶ added in v0.4.27
func (rt *RuntimeBehavior) CurrentContextCache() iface.Cache
CurrentContextCache 返回仅供运行时 goroutine 使用的上下文接口缓存。
func (*RuntimeBehavior) InstanceFaceCache ¶ added in v0.4.25
func (rt *RuntimeBehavior) InstanceFaceCache() iface.Cache
InstanceFaceCache 返回运行时实例的接口缓存,用于 reinterpret.Cast。
func (*RuntimeBehavior) PushPost ¶ added in v0.4.27
func (rt *RuntimeBehavior) PushPost(fun generic.ActionVar1[runtime.Context, any], args ...any) error
func (*RuntimeBehavior) PushPostDelegate ¶ added in v0.4.27
func (rt *RuntimeBehavior) PushPostDelegate(fun generic.DelegateVoidVar1[runtime.Context, any], args ...any) error
func (*RuntimeBehavior) PushSubmit ¶ added in v0.4.27
func (*RuntimeBehavior) PushSubmitDelegate ¶ added in v0.4.27
func (*RuntimeBehavior) PushSubmitDelegateVoid ¶ added in v0.4.27
func (rt *RuntimeBehavior) PushSubmitDelegateVoid(fun generic.DelegateVoidVar1[runtime.Context, any], args ...any) async.Future
func (*RuntimeBehavior) PushSubmitVoid ¶ added in v0.4.27
func (rt *RuntimeBehavior) PushSubmitVoid(fun generic.ActionVar1[runtime.Context, any], args ...any) async.Future
func (*RuntimeBehavior) Run ¶
func (rt *RuntimeBehavior) Run() async.Signal
Run 在新 goroutine 中启动运行时循环,并返回运行时终止时完成的 Signal。 运行时只能启动一次;上下文已经取消或运行时已经启动时会 panic。
func (*RuntimeBehavior) Stats ¶ added in v0.4.25
func (rt *RuntimeBehavior) Stats() RuntimeStats
Stats 返回 Runtime 的并发安全、近似瞬时统计快照。
func (*RuntimeBehavior) Terminate ¶
func (rt *RuntimeBehavior) Terminate() async.Signal
Terminate 请求停止运行时,并返回运行时终止时完成的 Signal。
func (*RuntimeBehavior) Terminated ¶ added in v0.3.33
func (rt *RuntimeBehavior) Terminated() async.Signal
Terminated 返回运行时终止时完成的 Signal。
type RuntimeHealthStats ¶ added in v0.4.27
type RuntimeHealthStats struct {
LastProgressTime int64 // 最近一次开始或完成任务的 UnixNano。
BlockedFutureID uint64 // 最近由 Runtime Context 尝试阻塞等待的 Future ID。
LastWaitRejectID uint64 // 最近一次被自等待规则拒绝的 Future ID。
}
RuntimeHealthStats 描述 Runtime 当前执行健康状态。
type RuntimeOptions ¶
type RuntimeOptions struct {
InstanceFace iface.Face[Runtime] // 自定义运行时实例及其接口缓存。
AutoRun bool // 是否在 RunningEvent_Birth 后自动启动运行时。
ContinueOnActivatingEntityPanic bool // 激活实体发生 panic 后是否继续;为 false 时销毁该实体。
Frame FrameOptions // 帧循环配置。
TaskQueue TaskQueueOptions // 任务队列配置。
GCInterval time.Duration // 两次运行时 GC 之间的最短间隔。
CustomGC CustomGC // 内置清理完成后执行的自定义 GC。
}
RuntimeOptions 定义创建运行时及其工作循环时使用的选项。
type RuntimeStats ¶ added in v0.4.25
type RuntimeStats struct {
WaitGroupCount int64
WaitGroupClosed bool
Tasks RuntimeTaskStats
Scope async.ScopeStats
Health RuntimeHealthStats
}
RuntimeStats 描述 Runtime 的生命周期、邮箱、异步作用域和健康状态快照。 各字段通过独立原子读取获得,不保证是同一时刻的事务快照。
type RuntimeTaskStats ¶ added in v0.4.27
type RuntimeTaskStats struct {
Submit TaskQueueStats
Post TaskQueueStats
Frame TaskQueueStats
}
RuntimeTaskStats 按 Submit、Post 和 Frame 三种调度语义分类。
type Service ¶
type Service interface {
reinterpret.InstanceProvider
// Context 返回绑定的服务上下文。
Context() service.Context
// contains filtered or unexported methods
}
Service 编排服务上下文的启动与停止生命周期。
func NewService ¶
NewService 创建服务并将 svcCtx 绑定到该服务。 同一个服务上下文只能绑定一次;创建期间会同步触发 RunningEvent_Birth。
func UnsafeNewService
deprecated
func UnsafeNewService(svcCtx service.Context, options ServiceOptions) Service
Deprecated: UnsafeNewService 仅供框架内部使用,请改用 NewService。
type ServiceBehavior ¶
type ServiceBehavior struct {
// contains filtered or unexported fields
}
ServiceBehavior 提供 Service 的默认实现。 扩展服务类型时应匿名嵌入该类型,并通过 InstanceFace 传入扩展实例。
func (*ServiceBehavior) Context ¶ added in v0.4.25
func (svc *ServiceBehavior) Context() service.Context
Context 返回绑定的服务上下文。
func (*ServiceBehavior) InstanceFaceCache ¶ added in v0.4.25
func (svc *ServiceBehavior) InstanceFaceCache() iface.Cache
InstanceFaceCache 返回服务实例的接口缓存,用于 reinterpret.Cast。
func (*ServiceBehavior) Run ¶
func (svc *ServiceBehavior) Run() async.Signal
Run 在新 goroutine 中启动服务循环,并返回服务终止时完成的 Signal。 服务只能启动一次;上下文已经取消或服务已经启动时会 panic。
func (*ServiceBehavior) Stats ¶ added in v0.4.25
func (svc *ServiceBehavior) Stats() ServiceStats
Stats 返回服务统计信息的当前快照。
func (*ServiceBehavior) Terminate ¶
func (svc *ServiceBehavior) Terminate() async.Signal
Terminate 请求停止服务,并返回服务终止时完成的 Signal。
func (*ServiceBehavior) Terminated ¶ added in v0.3.33
func (svc *ServiceBehavior) Terminated() async.Signal
Terminated 返回服务终止时完成的 Signal。
type ServiceOptions ¶
ServiceOptions 定义创建服务时使用的选项。
type ServiceStats ¶ added in v0.4.25
type ServiceStats struct {
WaitGroupCount int64 // 尚未完成的等待组任务数。
WaitGroupClosed bool // 等待组是否已经关闭并拒绝新任务。
}
ServiceStats 描述服务当前的等待组状态。
type TaskQueueOptions ¶ added in v0.4.25
TaskQueueOptions 定义运行时任务队列的容量策略。
type TaskQueueStats ¶ added in v0.4.25
type TaskQueueStats struct {
Accepted int64 // 成功进入队列的任务总数。
Queued int64 // 当前仅在队列中等待的任务数。
Running int64 // 当前正在执行的任务数。
Completed int64 // 已进入终态的任务总数。
Canceled int64 // Completed 中因调度上下文取消结束的数量。
Panicked int64 // Completed 中恢复过 panic 的数量。
RejectedClosed int64 // 因队列关闭而拒绝的数量。
RejectedFull int64 // 因有界队列容量不足而拒绝的数量。
}
TaskQueueStats 描述一种调度语义的 Runtime 邮箱统计。
Source Files
¶
- async.go
- continue.go
- doc.go
- entitycreator.go
- entityptcreator.go
- errors.go
- lifecycle_addin.go
- lifecycle_component.go
- lifecycle_entity.go
- options.go
- runtime.go
- runtime_callee.go
- runtime_event.gen.go
- runtime_event.go
- runtime_eventtab.gen.go
- runtime_frame.go
- runtime_frame_options.go
- runtime_gc.go
- runtime_lifecycle_caller.go
- runtime_looping_noframe.go
- runtime_looping_realtime.go
- runtime_options.go
- runtime_running.go
- runtime_stats.go
- runtime_task.go
- runtime_taskqueue.go
- runtime_taskqueue_options.go
- service.go
- service_options.go
- service_running.go
- service_stats.go
- unsafe_runtime.go
- unsafe_service.go
- worker.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package define 为插件声明提供类型安全的辅助定义。
|
Package define 为插件声明提供类型安全的辅助定义。 |
|
Package ec 定义实体—组件模型及其生命周期状态。
|
Package ec 定义实体—组件模型及其生命周期状态。 |
|
pt
Package pt 提供实体与组件原型库。
|
Package pt 提供实体与组件原型库。 |
|
Package event 提供进程内同步信号式事件基础设施。
|
Package event 提供进程内同步信号式事件基础设施。 |
|
eventc
command
Command eventc 是 Golaxy 的信号式事件代码生成工具。
|
Command eventc 是 Golaxy 的信号式事件代码生成工具。 |
|
Package extension 定义插件的公共协议与辅助函数。
|
Package extension 定义插件的公共协议与辅助函数。 |
|
Package runtime 定义运行时级上下文。
|
Package runtime 定义运行时级上下文。 |
|
Package service 定义服务级上下文。
|
Package service 定义服务级上下文。 |
|
Package utils 是核心工具包的命名空间根目录。
|
Package utils 是核心工具包的命名空间根目录。 |
|
assertion
Package assertion 提供基于实体组件模型的断言与注入辅助。
|
Package assertion 提供基于实体组件模型的断言与注入辅助。 |
|
async
Package async 提供一次性结果、完成信号、连续流和结构化异步作用域。
|
Package async 提供一次性结果、完成信号、连续流和结构化异步作用域。 |
|
corectx
Package corectx 定义 service 与 runtime 共用的上下文契约。
|
Package corectx 定义 service 与 runtime 共用的上下文契约。 |
|
exception
Package exception 提供带调用位置信息的错误与 panic 辅助。
|
Package exception 提供带调用位置信息的错误与 panic 辅助。 |
|
generic
Package generic 提供框架内部常用的泛型基础设施。
|
Package generic 提供框架内部常用的泛型基础设施。 |
|
iface
Package iface 提供接口缓存与 Face 封装。
|
Package iface 提供接口缓存与 Face 封装。 |
|
meta
Package meta 提供按字符串键排序的元数据映射。
|
Package meta 提供按字符串键排序的元数据映射。 |
|
option
Package option 提供泛型选项构造器。
|
Package option 提供泛型选项构造器。 |
|
reinterpret
Package reinterpret 提供基于实例缓存的接口重新解释。
|
Package reinterpret 提供基于实例缓存的接口重新解释。 |
|
types
Package types 提供反射类型辅助函数。
|
Package types 提供反射类型辅助函数。 |
|
uid
Package uid 提供框架统一使用的全局唯一 ID 类型。
|
Package uid 提供框架统一使用的全局唯一 ID 类型。 |