Documentation ¶
Overview ¶
Package core Golaxy分布式服务开发框架的内核,主要提供Actor线程模型(Actor Model)和EC组件框架(Entity-Component)。
- 使用EC组件框架(Entity-Component)组织代码结构。
- 并发模式基于Actor编程模型,实体(Entity)就是Actor,其中组件(Component)用于实现状态(state)与行为(behavior),运行时(Runtime)中的任务处理流水线就是邮箱(mailbox), 实体的Id就是邮箱地址(mailbox address),服务上下文(Service context)提供的全局实体管理功能,可以用于投递邮件(mail)给Actor。不同于传统Actor编程模型的地方是 多个Actor可以使用同个邮箱,也就是多个实体可以加入同个运行时,在同个线程中运行。
- 一些分布式系统常用的依赖项,例如服务发现(Service Discovery)、消息队列与事件驱动架构(MQ and Broker)、分布式锁(Distributed Sync)等分布式服务特性,这些特性将会以官方插件形式提供。
Index ¶
- Variables
- func Async(provider ictx.ConcurrentContextProvider, ...) async.AsyncRet
- func AsyncVoid(provider ictx.ConcurrentContextProvider, ...) async.AsyncRet
- func Go(ctx context.Context, fun generic.FuncVar1[context.Context, any, async.Ret], ...) async.AsyncRet
- func GoVoid(ctx context.Context, fun generic.ActionVar1[context.Context, any], args ...any) async.AsyncRet
- func ReadChan[T any](ctx context.Context, ch <-chan T) async.AsyncRet
- func TimeAfter(ctx context.Context, dur time.Duration) async.AsyncRet
- func TimeAt(ctx context.Context, at time.Time) async.AsyncRet
- func TimeTick(ctx context.Context, dur time.Duration) async.AsyncRet
- func UnsafeRuntime(runtime Runtime) _UnsafeRuntimedeprecated
- func UnsafeService(service Service) _UnsafeServicedeprecated
- type AwaitDirector
- func (ad AwaitDirector) All(fun generic.ActionVar2[runtime.Context, []async.Ret, any], args ...any)
- func (ad AwaitDirector) Any(fun generic.ActionVar2[runtime.Context, async.Ret, any], args ...any)
- func (ad AwaitDirector) AnyOK(fun generic.ActionVar2[runtime.Context, async.Ret, any], args ...any)
- func (ad AwaitDirector) Pipe(ctx context.Context, fun generic.ActionVar2[runtime.Context, async.Ret, any], ...)
- type CustomGC
- type EntityCreator
- func (c EntityCreator) AwakeOnFirstAccess(b bool) EntityCreator
- func (c EntityCreator) Instance(instance ec.Entity) EntityCreator
- func (c EntityCreator) InstanceFace(face iface.Face[ec.Entity]) EntityCreator
- func (c EntityCreator) Meta(m meta.Meta) EntityCreator
- func (c EntityCreator) ParentId(id uid.Id) EntityCreator
- func (c EntityCreator) PersistId(id uid.Id) EntityCreator
- func (c EntityCreator) Scope(scope ec.Scope) EntityCreator
- func (c EntityCreator) Spawn() (ec.Entity, error)
- type EntityPTCreator
- func (c EntityPTCreator) AddComponent(comp any, name ...string) EntityPTCreator
- func (c EntityPTCreator) AwakeOnFirstAccess(b bool) EntityPTCreator
- func (c EntityPTCreator) Declare()
- func (c EntityPTCreator) Instance(instance any) EntityPTCreator
- func (c EntityPTCreator) Redeclare()
- func (c EntityPTCreator) Scope(scope ec.Scope) EntityPTCreator
- type LifecycleComponentAwake
- type LifecycleComponentDispose
- type LifecycleComponentLateUpdate
- type LifecycleComponentShut
- type LifecycleComponentStart
- type LifecycleComponentUpdate
- type LifecycleEntityAwake
- type LifecycleEntityDispose
- type LifecycleEntityLateUpdate
- type LifecycleEntityShut
- type LifecycleEntityStart
- type LifecycleEntityUpdate
- type LifecycleRuntimePluginInit
- type LifecycleRuntimePluginShut
- type LifecycleServicePluginInit
- type LifecycleServicePluginShut
- type Runtime
- type RuntimeBehavior
- func (rt *RuntimeBehavior) GetConcurrentContext() iface.Cache
- func (rt *RuntimeBehavior) GetCurrentContext() iface.Cache
- func (rt *RuntimeBehavior) GetInstanceFaceCache() iface.Cache
- func (rt *RuntimeBehavior) OnComponentDestroySelf(comp ec.Component)
- func (rt *RuntimeBehavior) OnEntityDestroySelf(entity ec.Entity)
- func (rt *RuntimeBehavior) OnEntityMgrAddEntity(entityMgr runtime.EntityMgr, entity ec.Entity)
- func (rt *RuntimeBehavior) OnEntityMgrEntityAddComponents(entityMgr runtime.EntityMgr, entity ec.Entity, components []ec.Component)
- func (rt *RuntimeBehavior) OnEntityMgrEntityFirstAccessComponent(entityMgr runtime.EntityMgr, entity ec.Entity, component ec.Component)
- func (rt *RuntimeBehavior) OnEntityMgrEntityRemoveComponent(entityMgr runtime.EntityMgr, entity ec.Entity, component ec.Component)
- func (rt *RuntimeBehavior) OnEntityMgrRemoveEntity(entityMgr runtime.EntityMgr, entity ec.Entity)
- func (rt *RuntimeBehavior) PushCall(fun generic.FuncVar0[any, async.Ret], args ...any) async.AsyncRet
- func (rt *RuntimeBehavior) PushCallDelegate(fun generic.DelegateFuncVar0[any, async.Ret], args ...any) async.AsyncRet
- func (rt *RuntimeBehavior) PushCallVoid(fun generic.ActionVar0[any], args ...any) async.AsyncRet
- func (rt *RuntimeBehavior) PushCallVoidDelegate(fun generic.DelegateActionVar0[any], args ...any) async.AsyncRet
- func (rt *RuntimeBehavior) Run() <-chan struct{}
- func (rt *RuntimeBehavior) Terminate() <-chan struct{}
- func (rt *RuntimeBehavior) Terminated() <-chan struct{}
- type RuntimeOptions
- type Service
- type ServiceBehavior
- type ServiceOptions
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 ( ErrProcessQueueClosed = fmt.Errorf("%w: process queue is closed", ErrRuntime) // 任务处理流水线关闭 ErrProcessQueueFull = fmt.Errorf("%w: process queue is full", ErrRuntime) // 任务处理流水线已满 )
var (
ErrAllFailures = fmt.Errorf("%w: all of async result failures", ErrCore)
)
var With _Option
Functions ¶
func Async ¶
func Async(provider ictx.ConcurrentContextProvider, fun generic.FuncVar1[runtime.Context, any, async.Ret], args ...any) async.AsyncRet
Async 异步执行代码,有返回值
func AsyncVoid ¶
func AsyncVoid(provider ictx.ConcurrentContextProvider, fun generic.ActionVar1[runtime.Context, any], args ...any) async.AsyncRet
AsyncVoid 异步执行代码,无返回值
func Go ¶
func Go(ctx context.Context, fun generic.FuncVar1[context.Context, any, async.Ret], args ...any) async.AsyncRet
Go 使用新线程执行代码,有返回值
func GoVoid ¶
func GoVoid(ctx context.Context, fun generic.ActionVar1[context.Context, any], args ...any) async.AsyncRet
GoVoid 使用新线程执行代码,无返回值
func UnsafeRuntime
deprecated
func UnsafeRuntime(runtime Runtime) _UnsafeRuntime
Deprecated: UnsafeRuntime 访问运行时内部方法
func UnsafeService
deprecated
func UnsafeService(service Service) _UnsafeService
Deprecated: UnsafeService 访问服务内部方法
Types ¶
type AwaitDirector ¶
type AwaitDirector struct {
// contains filtered or unexported fields
}
AwaitDirector 异步等待分发器
func Await ¶
func Await(provider ictx.CurrentContextProvider, asyncRet ...async.AsyncRet) AwaitDirector
Await 异步等待结果返回
func (AwaitDirector) All ¶
func (ad AwaitDirector) All(fun generic.ActionVar2[runtime.Context, []async.Ret, any], args ...any)
All 异步等待所有结果返回
func (AwaitDirector) Any ¶
func (ad AwaitDirector) Any(fun generic.ActionVar2[runtime.Context, async.Ret, any], args ...any)
Any 异步等待任意一个结果返回
type CustomGC ¶
type CustomGC = generic.DelegateAction1[Runtime] // 自定义GC函数
type EntityCreator ¶
type EntityCreator struct {
// contains filtered or unexported fields
}
EntityCreator 实体构建器
func CreateEntity ¶
func CreateEntity(provider ictx.CurrentContextProvider, prototype string) EntityCreator
CreateEntity 创建实体
func (EntityCreator) AwakeOnFirstAccess ¶ added in v0.2.38
func (c EntityCreator) AwakeOnFirstAccess(b bool) EntityCreator
AwakeOnFirstAccess 设置开启组件被首次访问时,检测并调用Awake()
func (EntityCreator) Instance ¶ added in v0.3.34
func (c EntityCreator) Instance(instance ec.Entity) EntityCreator
Instance 设置实例,用于扩展实体能力
func (EntityCreator) InstanceFace ¶ added in v0.3.34
func (c EntityCreator) InstanceFace(face iface.Face[ec.Entity]) EntityCreator
InstanceFace 设置实例,用于扩展实体能力
func (EntityCreator) Meta ¶ added in v0.2.38
func (c EntityCreator) Meta(m meta.Meta) EntityCreator
Meta 设置Meta信息
func (EntityCreator) ParentId ¶ added in v0.2.38
func (c EntityCreator) ParentId(id uid.Id) EntityCreator
ParentId 设置父实体Id
func (EntityCreator) PersistId ¶ added in v0.2.38
func (c EntityCreator) PersistId(id uid.Id) EntityCreator
PersistId 设置实体持久化Id
func (EntityCreator) Scope ¶ added in v0.2.38
func (c EntityCreator) Scope(scope ec.Scope) EntityCreator
Scope 设置实体的可访问作用域
type EntityPTCreator ¶ added in v0.2.39
type EntityPTCreator struct {
// contains filtered or unexported fields
}
EntityPTCreator 实体原型构建器
func CreateEntityPT ¶ added in v0.2.39
func CreateEntityPT(svcCtx service.Context, prototype string) EntityPTCreator
CreateEntityPT 创建实体原型
func (EntityPTCreator) AddComponent ¶ added in v0.2.39
func (c EntityPTCreator) AddComponent(comp any, name ...string) EntityPTCreator
AddComponent 添加组件
func (EntityPTCreator) AwakeOnFirstAccess ¶ added in v0.2.80
func (c EntityPTCreator) AwakeOnFirstAccess(b bool) EntityPTCreator
AwakeOnFirstAccess 设置开启组件被首次访问时,检测并调用Awake()
func (EntityPTCreator) Instance ¶ added in v0.3.34
func (c EntityPTCreator) Instance(instance any) EntityPTCreator
Instance 设置实例,用于扩展实体能力
func (EntityPTCreator) Redeclare ¶ added in v0.3.42
func (c EntityPTCreator) Redeclare()
Redeclare 重新声明实体原型
func (EntityPTCreator) Scope ¶ added in v0.2.80
func (c EntityPTCreator) Scope(scope ec.Scope) EntityPTCreator
Scope 设置实体的可访问作用域
type LifecycleComponentAwake ¶
type LifecycleComponentAwake interface {
Awake()
}
LifecycleComponentAwake 组件的生命周期进入唤醒(awake)时的回调,组件实现此接口即可使用
type LifecycleComponentDispose ¶
type LifecycleComponentDispose interface {
Dispose()
}
LifecycleComponentDispose 组件的生命周期进入死亡(death)时的回调,组件实现此接口即可使用
type LifecycleComponentLateUpdate ¶
type LifecycleComponentLateUpdate = eventLateUpdate
LifecycleComponentLateUpdate 如果开启运行时的帧更新特性,那么组件状态为活跃(alive)时,将会收到这个帧迟滞更新(late update)回调,组件实现此接口即可使用
type LifecycleComponentShut ¶
type LifecycleComponentShut interface {
Shut()
}
LifecycleComponentShut 组件的生命周期进入结束(shut)时的回调,组件实现此接口即可使用
type LifecycleComponentStart ¶
type LifecycleComponentStart interface {
Start()
}
LifecycleComponentStart 组件的生命周期进入开始(start)时的回调,组件实现此接口即可使用
type LifecycleComponentUpdate ¶
type LifecycleComponentUpdate = eventUpdate
LifecycleComponentUpdate 如果开启运行时的帧更新特性,那么组件状态为活跃(alive)时,将会收到这个帧更新(update)回调,组件实现此接口即可使用
type LifecycleEntityAwake ¶
type LifecycleEntityAwake interface {
Awake()
}
LifecycleEntityAwake 实体的生命周期进入唤醒(awake)时的回调,实体实现此接口即可使用
type LifecycleEntityDispose ¶
type LifecycleEntityDispose interface {
Dispose()
}
LifecycleEntityDispose 实体的生命周期进入死亡(death)时的回调,实体实现此接口即可使用
type LifecycleEntityLateUpdate ¶
type LifecycleEntityLateUpdate = eventLateUpdate
LifecycleEntityLateUpdate 如果开启运行时的帧更新特性,那么实体状态为活跃(alive)时,将会收到这个帧迟滞更新(late update)回调,实体实现此接口即可使用
type LifecycleEntityShut ¶
type LifecycleEntityShut interface {
Shut()
}
LifecycleEntityShut 实体的生命周期进入结束(shut)时的回调,实体实现此接口即可使用
type LifecycleEntityStart ¶
type LifecycleEntityStart interface {
Start()
}
LifecycleEntityStart 实体的生命周期进入开始(start)时的回调,实体实现此接口即可使用
type LifecycleEntityUpdate ¶
type LifecycleEntityUpdate = eventUpdate
LifecycleEntityUpdate 如果开启运行时的帧更新特性,那么实体状态为活跃(alive)时,将会收到这个帧更新(update)回调,实体实现此接口即可使用
type LifecycleRuntimePluginInit ¶
LifecycleRuntimePluginInit 运行时上的插件初始化回调,插件实现此接口即可使用
type LifecycleRuntimePluginShut ¶
LifecycleRuntimePluginShut 运行时上的插件结束回调,插件实现此接口即可使用
type LifecycleServicePluginInit ¶
LifecycleServicePluginInit 服务上的插件初始化回调,插件实现此接口即可使用
type LifecycleServicePluginShut ¶
LifecycleServicePluginShut 服务上的插件结束回调,插件实现此接口即可使用
type Runtime ¶
type Runtime interface { ictx.CurrentContextProvider ictx.ConcurrentContextProvider reinterpret.InstanceProvider async.Callee // contains filtered or unexported methods }
Runtime 运行时接口
func NewRuntime ¶
NewRuntime 创建运行时
func UnsafeNewRuntime
deprecated
func UnsafeNewRuntime(rtCtx runtime.Context, options RuntimeOptions) Runtime
Deprecated: UnsafeNewRuntime 内部创建运行时
type RuntimeBehavior ¶
type RuntimeBehavior struct {
// contains filtered or unexported fields
}
RuntimeBehavior 运行时行为,在扩展运行时能力时,匿名嵌入至运行时结构体中
func (*RuntimeBehavior) GetConcurrentContext ¶
func (rt *RuntimeBehavior) GetConcurrentContext() iface.Cache
GetConcurrentContext 获取多线程安全的上下文
func (*RuntimeBehavior) GetCurrentContext ¶
func (rt *RuntimeBehavior) GetCurrentContext() iface.Cache
GetCurrentContext 获取当前上下文
func (*RuntimeBehavior) GetInstanceFaceCache ¶ added in v0.3.34
func (rt *RuntimeBehavior) GetInstanceFaceCache() iface.Cache
GetInstanceFaceCache 支持重新解释类型
func (*RuntimeBehavior) OnComponentDestroySelf ¶
func (rt *RuntimeBehavior) OnComponentDestroySelf(comp ec.Component)
OnComponentDestroySelf 事件处理器:组件销毁自身
func (*RuntimeBehavior) OnEntityDestroySelf ¶
func (rt *RuntimeBehavior) OnEntityDestroySelf(entity ec.Entity)
OnEntityDestroySelf 事件处理器:实体销毁自身
func (*RuntimeBehavior) OnEntityMgrAddEntity ¶
func (rt *RuntimeBehavior) OnEntityMgrAddEntity(entityMgr runtime.EntityMgr, entity ec.Entity)
OnEntityMgrAddEntity 事件处理器:实体管理器添加实体
func (*RuntimeBehavior) OnEntityMgrEntityAddComponents ¶
func (rt *RuntimeBehavior) OnEntityMgrEntityAddComponents(entityMgr runtime.EntityMgr, entity ec.Entity, components []ec.Component)
OnEntityMgrEntityAddComponents 事件处理器:实体管理器中的实体添加组件
func (*RuntimeBehavior) OnEntityMgrEntityFirstAccessComponent ¶
func (rt *RuntimeBehavior) OnEntityMgrEntityFirstAccessComponent(entityMgr runtime.EntityMgr, entity ec.Entity, component ec.Component)
OnEntityMgrEntityFirstAccessComponent 事件处理器:实体管理器中的实体首次访问组件
func (*RuntimeBehavior) OnEntityMgrEntityRemoveComponent ¶
func (rt *RuntimeBehavior) OnEntityMgrEntityRemoveComponent(entityMgr runtime.EntityMgr, entity ec.Entity, component ec.Component)
OnEntityMgrEntityRemoveComponent 事件处理器:实体管理器中的实体删除组件
func (*RuntimeBehavior) OnEntityMgrRemoveEntity ¶
func (rt *RuntimeBehavior) OnEntityMgrRemoveEntity(entityMgr runtime.EntityMgr, entity ec.Entity)
OnEntityMgrRemoveEntity 事件处理器:实体管理器删除实体
func (*RuntimeBehavior) PushCall ¶
func (rt *RuntimeBehavior) PushCall(fun generic.FuncVar0[any, async.Ret], args ...any) async.AsyncRet
PushCall 将调用函数压入接受者的任务处理流水线,返回AsyncRet。
func (*RuntimeBehavior) PushCallDelegate ¶
func (rt *RuntimeBehavior) PushCallDelegate(fun generic.DelegateFuncVar0[any, async.Ret], args ...any) async.AsyncRet
PushCallDelegate 将调用委托压入接受者的任务处理流水线,返回AsyncRet。
func (*RuntimeBehavior) PushCallVoid ¶
func (rt *RuntimeBehavior) PushCallVoid(fun generic.ActionVar0[any], args ...any) async.AsyncRet
PushCallVoid 将调用函数压入接受者的任务处理流水线,返回AsyncRet。
func (*RuntimeBehavior) PushCallVoidDelegate ¶
func (rt *RuntimeBehavior) PushCallVoidDelegate(fun generic.DelegateActionVar0[any], args ...any) async.AsyncRet
PushCallVoidDelegate 将调用委托压入接受者的任务处理流水线,返回AsyncRet。
func (*RuntimeBehavior) Terminate ¶
func (rt *RuntimeBehavior) Terminate() <-chan struct{}
Terminate 停止
func (*RuntimeBehavior) Terminated ¶ added in v0.3.33
func (rt *RuntimeBehavior) Terminated() <-chan struct{}
Terminated 已停止
type RuntimeOptions ¶
type RuntimeOptions struct { InstanceFace iface.Face[Runtime] // 实例,用于扩展运行时能力 AutoRun bool // 是否开启自动运行 ProcessQueueCapacity int // 任务处理流水线大小 Frame runtime.Frame // 帧,设置为nil表示不使用帧更新特性 GCInterval time.Duration // GC间隔时长 CustomGC CustomGC // 自定义GC }
RuntimeOptions 创建运行时的所有选项
type Service ¶
type Service interface { reinterpret.InstanceProvider // GetContext 获取服务上下文 GetContext() service.Context // contains filtered or unexported methods }
Service 服务
func NewService ¶
NewService 创建服务
func UnsafeNewService
deprecated
func UnsafeNewService(svcCtx service.Context, options ServiceOptions) Service
Deprecated: UnsafeNewService 内部创建服务
type ServiceBehavior ¶
type ServiceBehavior struct {
// contains filtered or unexported fields
}
func (*ServiceBehavior) GetContext ¶
func (svc *ServiceBehavior) GetContext() service.Context
GetContext 获取服务上下文
func (*ServiceBehavior) GetInstanceFaceCache ¶ added in v0.3.34
func (svc *ServiceBehavior) GetInstanceFaceCache() iface.Cache
GetInstanceFaceCache 支持重新解释类型
func (*ServiceBehavior) Terminate ¶
func (svc *ServiceBehavior) Terminate() <-chan struct{}
Terminate 停止
func (*ServiceBehavior) Terminated ¶ added in v0.3.33
func (svc *ServiceBehavior) Terminated() <-chan struct{}
Terminated 已停止
type ServiceOptions ¶
ServiceOptions 创建服务的所有选项
Source Files ¶
- async.go
- await.go
- doc.go
- entitycreator.go
- entityptcreator.go
- errors.go
- lifecycle_component.go
- lifecycle_entity.go
- lifecycle_plugin.go
- options.go
- running.go
- runtime.go
- runtime_callee.go
- runtime_event.gen.go
- runtime_event.go
- runtime_gc.go
- runtime_looping_noframe.go
- runtime_looping_realtime.go
- runtime_options.go
- runtime_running.go
- runtime_task.go
- service.go
- service_options.go
- service_running.go
- unsafe_runtime.go
- unsafe_service.go
Directories ¶
Path | Synopsis |
---|---|
Package define 利用泛型特性,简化代码编写。
|
Package define 利用泛型特性,简化代码编写。 |
Package ec 提供了一个EC(Entity-Component)组件框架,用于帮助开发者组织代码架构。
|
Package ec 提供了一个EC(Entity-Component)组件框架,用于帮助开发者组织代码架构。 |
Package event 高效的事件系统,适用于单线程环境,需要使用go:generate功能来生成代码。
|
Package event 高效的事件系统,适用于单线程环境,需要使用go:generate功能来生成代码。 |
eventc
Package eventc 使用go:generate功能,在编译前自动化生成代码
|
Package eventc 使用go:generate功能,在编译前自动化生成代码 |
internal
|
|
Package plugin 插件,用于开发一些需要使用单例模式设计的功能,例如服务发现、消息队列与日志系统等。
|
Package plugin 插件,用于开发一些需要使用单例模式设计的功能,例如服务发现、消息队列与日志系统等。 |
Package pt 实体与组件原型,用于创建实例。
|
Package pt 实体与组件原型,用于创建实例。 |
Package runtime 运行时环境提供的一些接口与函数。
|
Package runtime 运行时环境提供的一些接口与函数。 |
Package service 运行时环境提供的一些接口与函数。
|
Package service 运行时环境提供的一些接口与函数。 |
Package utils 一些工具类与函数。
|
Package utils 一些工具类与函数。 |