Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component[T any] struct { // contains filtered or unexported fields }
Component 泛型懒加载组件容器 T 为底层 manager 类型(如 redisutil.RedisManager)
并发语义:
- Get() 热路径完全无锁:通过 atomic.Pointer.Load 读取已初始化的值
- 首次初始化通过 mu 互斥 + 双检,保证 factory 只成功执行一次
- factory 失败不缓存,下次 Get() 会重新尝试(与原 sync.Once 重置语义一致)
- 相较原 sync.Once+重置方案,修复了 factory 失败与并发 Get 之间的 data race 及可能返回 (零值, nil) 的正确性问题
func NewComponent ¶
NewComponent 创建组件容器
type ComponentGroup ¶
type ComponentGroup[T any] struct { // contains filtered or unexported fields }
ComponentGroup 管理同类型组件的多个命名实例
并发语义:
- Get(name) 热路径使用 RWMutex 的读锁,多个 goroutine 可并发读已存在实例
- 首次创建某个命名实例时升级为写锁,通过双检避免重复创建
- 底层 Component.Get 仍保持无锁快速路径
func NewComponentGroup ¶
func NewComponentGroup[T any](baseType string, factoryFn func(name string) func() (T, error), lc *Lifecycle) *ComponentGroup[T]
NewComponentGroup 创建命名实例容器
func (*ComponentGroup[T]) Get ¶
func (g *ComponentGroup[T]) Get(name string) (T, error)
Get 获取指定名称的实例,首次调用时创建 Component 并懒加载
Click to show internal directories.
Click to hide internal directories.