Documentation
¶
Overview ¶
Package events 提供了简单的事件发布订阅功能
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrStopped = errors.New("该事件已经停止发布新内容")
ErrStopped 表示发布都已经调用 Destory 销毁了事件处理器。
Functions ¶
Types ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event 事件
func (*Event) Attach ¶
func (e *Event) Attach(subscriber Subscriber) int
Attach 注册订阅者
返回一个唯一 ID,用户可以使用此 ID 取消订阅
type Publisher ¶
type Publisher struct {
// contains filtered or unexported fields
}
Publisher 事件的发布者
type Subscriber ¶
type Subscriber func(data interface{})
Subscriber 订阅者函数
当存在多个订阅者时,通过 go 异步执行每个函数。
data 为事件传递过来的数据,可能存在多个订阅者, 最好不要直接修改 data 数据,否则结果是未知的。
Click to show internal directories.
Click to hide internal directories.