Documentation
¶
Index ¶
- func Close() error
- func Publish(ctx context.Context, topic string, message any) error
- func SetContextProvider(provider ContextProvider)
- func SetEventbus(eb Eventbus)
- func Subscribe(ctx context.Context, topic string, handler EventHandler) error
- func Unsubscribe(ctx context.Context, topic string, handler EventHandler) error
- type ContextProvider
- type Event
- type EventHandler
- type Eventbus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetContextProvider ¶ added in v1.0.9
func SetContextProvider(provider ContextProvider)
SetContextProvider 设置 Context 提供者(由 dawn 包调用)
func Subscribe ¶
func Subscribe(ctx context.Context, topic string, handler EventHandler) error
Subscribe 订阅事件
func Unsubscribe ¶
func Unsubscribe(ctx context.Context, topic string, handler EventHandler) error
Unsubscribe 取消订阅
Types ¶
type ContextProvider ¶ added in v1.0.9
type ContextProvider interface {
// Eventbus 获取事件总线
Eventbus() Eventbus
}
ContextProvider Context 提供者接口,用于避免循环依赖
func GetContextProvider ¶ added in v1.0.9
func GetContextProvider() ContextProvider
GetContextProvider 获取 Context 提供者
type EventHandler ¶
type EventHandler = internal.EventHandler
type Eventbus ¶
type Eventbus interface {
// Close 关闭事件总线
Close() error
// Publish 发布事件
Publish(ctx context.Context, topic string, message any) error
// Subscribe 订阅事件
Subscribe(ctx context.Context, topic string, handler EventHandler) error
// Unsubscribe 取消订阅
Unsubscribe(ctx context.Context, topic string, handler EventHandler) error
}
func GetEventbus ¶
func GetEventbus() Eventbus
GetEventbus 获取事件总线 优先从 Context 获取,如果没有关联 Context 则使用全局变量
Click to show internal directories.
Click to hide internal directories.