Documentation ¶
Index ¶
- Constants
- func AddEvent(e IEvent) error
- func AsyncPublish(e IEvent)
- func HasEvent(name string) bool
- func HasListeners(name string) bool
- func Listen(name string, listener BaseListener, priority ...int) (err error)
- func ListenedNames() []string
- func Listeners() map[string]*ListenerQueue
- func ListenersCount(name string) int
- func Publish(e IEvent) error
- func PublishBatch(es ...interface{}) (ers []error)
- func RemoveEvent(name string)
- func RemoveEvents()
- func RemoveListeners(listener IListener)
- func RemoveListenersByName(name string)
- func Subscribe(listener IListener, priority ...int) (err error)
- func UnListen(name string, listener BaseListener)
- func UnSubscribe(listener IListener)
- type BaseListener
- type Event
- func (that *Event) Abort(abort bool)
- func (that *Event) AttachTo(m *EventBus) error
- func (that *Event) Data() map[interface{}]interface{}
- func (that *Event) Get(key interface{}) interface{}
- func (that *Event) IsAborted() bool
- func (that *Event) Name() string
- func (that *Event) Set(key interface{}, val interface{})
- func (that *Event) SetData(data map[interface{}]interface{}) IEvent
- func (that *Event) SetName(name string)
- type EventBus
- func (that *EventBus) AddEvent(e IEvent) error
- func (that *EventBus) AsyncPublish(e IEvent)
- func (that *EventBus) Clear()
- func (that *EventBus) Fire(name string, params map[interface{}]interface{}) (e IEvent, err error)
- func (that *EventBus) GetEvent(name string) (IEvent, bool)
- func (that *EventBus) HasEvent(name string) bool
- func (that *EventBus) HasListeners(name string) bool
- func (that *EventBus) Listen(name string, listener BaseListener, priority ...int) (err error)
- func (that *EventBus) ListenedNames() []string
- func (that *EventBus) Listeners() map[string]*ListenerQueue
- func (that *EventBus) ListenersByName(name string) *ListenerQueue
- func (that *EventBus) ListenersCount(name string) int
- func (that *EventBus) Publish(e IEvent) error
- func (that *EventBus) PublishBatch(es ...interface{}) (ers []error)
- func (that *EventBus) RemoveEvent(name string)
- func (that *EventBus) RemoveEvents()
- func (that *EventBus) RemoveListeners(listener BaseListener)
- func (that *EventBus) RemoveListenersByName(name string)
- func (that *EventBus) Reset()
- func (that *EventBus) Subscribe(listener IListener, priority ...int) (err error)
- func (that *EventBus) UnListen(name string, listener BaseListener)
- func (that *EventBus) UnSubscribe(listener IListener)
- type IEvent
- type IListener
- type ListenerFunc
- type ListenerItem
- type ListenerQueue
Constants ¶
const ( // Min 最低优先级 Min = -300 // Low 低优先级 Low = -200 // BelowNormal 相对低优先级 BelowNormal = -100 // Normal 正常优先级 Normal = 0 // AboveNormal 稍高优先级 AboveNormal = 100 // High 高优先级 High = 200 // Max 最高优先级 Max = 300 )
const Wildcard = "*"
Wildcard 事件名称,通配符,表示所有
Variables ¶
This section is empty.
Functions ¶
func Listen ¶
func Listen(name string, listener BaseListener, priority ...int) (err error)
Listen 监听事件 name: 事件名 listener:事件监听器 priority:监听优先级
func PublishBatch ¶
func PublishBatch(es ...interface{}) (ers []error)
PublishBatch 批量触发事件 Usage:
PublishBatch("name1", "name2", &MyEvent{})
func RemoveListenersByName ¶
func RemoveListenersByName(name string)
RemoveListenersByName 取消指定事件名的所有事件监听 name: 事件名
func UnListen ¶
func UnListen(name string, listener BaseListener)
UnListen 取消事件的监听 name: 事件名 listener:事件监听器
func UnSubscribe ¶
func UnSubscribe(listener IListener)
UnSubscribe 取消事件订阅 listener: 事件监听器,支持通过Listen()方法获取监听事件的名称
Types ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event 事件的基础实现
type EventBus ¶ added in v0.0.8
type EventBus struct {
// contains filtered or unexported fields
}
EventBus 事件管理器
func (*EventBus) AsyncPublish ¶ added in v0.0.8
AsyncPublish 异步触发事件
func (*EventBus) HasListeners ¶ added in v0.0.8
HasListeners 判断是否存在指定名称的监听
func (*EventBus) Listen ¶ added in v0.0.8
func (that *EventBus) Listen(name string, listener BaseListener, priority ...int) (err error)
Listen 监听事件
func (*EventBus) ListenedNames ¶ added in v0.0.8
ListenedNames 获取监听的事件名列表
func (*EventBus) Listeners ¶ added in v0.0.8
func (that *EventBus) Listeners() map[string]*ListenerQueue
Listeners 获取监听列表
func (*EventBus) ListenersByName ¶ added in v0.0.8
func (that *EventBus) ListenersByName(name string) *ListenerQueue
ListenersByName 获取指定事件名称的监听列表
func (*EventBus) ListenersCount ¶ added in v0.0.8
ListenersCount 获取指定名称的监听列表数量
func (*EventBus) PublishBatch ¶ added in v0.0.8
PublishBatch 批量触发事件 Usage:
PublishBatch("name1", "name2", &MyEvent{})
func (*EventBus) RemoveEvent ¶ added in v0.0.8
RemoveEvent 移除自定义事件
func (*EventBus) RemoveEvents ¶ added in v0.0.8
func (that *EventBus) RemoveEvents()
RemoveEvents 移除所有自定义事件
func (*EventBus) RemoveListeners ¶ added in v0.0.8
func (that *EventBus) RemoveListeners(listener BaseListener)
RemoveListeners 移除监听方法
func (*EventBus) RemoveListenersByName ¶ added in v0.0.8
RemoveListenersByName 清除所有指定事件名的事件监听器
func (*EventBus) UnListen ¶ added in v0.0.8
func (that *EventBus) UnListen(name string, listener BaseListener)
UnListen 移除事件监听
func (*EventBus) UnSubscribe ¶ added in v0.0.8
UnSubscribe 取消监听事件
type IEvent ¶
type IEvent interface { // Name 获取事件名 Name() string // Get 获取事件携带的参数 Get(key interface{}) interface{} // Set 设置事件参数 Set(key interface{}, val interface{}) // Data 获取事件的全部参数 Data() map[interface{}]interface{} // SetData 批量设置事件参数 SetData(map[interface{}]interface{}) IEvent // Abort 设置是否中途停止,设置为true,则表示执行到该监听器为止,后续监听器不在执行 Abort(bool) // IsAborted 判断是否要继续触发后续监听器 IsAborted() bool }
IEvent 事件的接口
type ListenerFunc ¶
ListenerFunc 强制把监听的方法转换成对象
func (ListenerFunc) Process ¶
func (fn ListenerFunc) Process(e IEvent) error
type ListenerItem ¶
type ListenerItem struct { Priority int Listener BaseListener }
ListenerItem 事件监听的数据结构
func NewListenerItem ¶
func NewListenerItem(listener BaseListener, priority int) *ListenerItem
NewListenerItem 新建事件监听条目
type ListenerQueue ¶
type ListenerQueue struct {
// contains filtered or unexported fields
}
ListenerQueue 监听队列,以优先级排序
func ListenersByName ¶
func ListenersByName(name string) *ListenerQueue
ListenersByName 获取指定事件名下的监听列表
func (*ListenerQueue) Remove ¶
func (that *ListenerQueue) Remove(listener BaseListener)
Remove 移除指定的监听