Documentation ¶
Index ¶
- Constants
- Variables
- func ListEvents() (events []string)
- func Publish(eventName string, event ...interface{})
- func RegistEvent(eventNames ...string) errors.ErrCode
- func Unsubscribe(eventName string, ids ...string) errors.ErrCode
- type Bus
- type Center
- func (p *Center) ListEvents() (events []string)
- func (p *Center) Name() string
- func (p *Center) Publish(eventName string, evts ...interface{})
- func (p *Center) RegistEvent(eventNames ...string) errors.ErrCode
- func (p *Center) Subscribe(eventName string, fn func(...interface{})) (*Subscriber, errors.ErrCode)
- func (p *Center) Unsubscribe(eventName string, ids ...string) errors.ErrCode
- func (p *Center) UnsubscribeAll(eventName string)
- type Predicate
- type Subscriber
- type SubscriberGroup
Constants ¶
View Source
const DefaultEventCenterName = "trellis::event::default-name"
DefaultEventCenterName default event center name
Variables ¶
View Source
var ( ErrCenterNameIsEmpty = errors.TN(_NamespaceEvent, 10001, "center name is empty") ErrEventNameIsEmpty = errors.TN(_NamespaceEvent, 10002, "event name is empty") ErrEventIsAlreadyRegisted = errors.TN(_NamespaceEvent, 10003, "event is already registed: {{.name}}") ErrToAddNonSubscriber = errors.TN(_NamespaceEvent, 10004, "to add non subscription") ErrToRemoveSubscriberID = errors.TN(_NamespaceEvent, 10005, "to remove non subscription by id") ErrCreateSubscriberID = errors.TN(_NamespaceEvent, 10006, "fail to create subscription") )
event errors
Functions ¶
Types ¶
type Bus ¶
type Bus interface { RegistEvent(eventNames ...string) errors.ErrCode Subscribe(eventName string, fn func(...interface{})) (*Subscriber, errors.ErrCode) Unsubscribe(eventName string, ids ...string) errors.ErrCode UnsubscribeAll(eventName string) Publish(eventName string, evt ...interface{}) ListEvents() (events []string) }
Bus xxx
type Center ¶
type Center struct {
// contains filtered or unexported fields
}
Center xxx
func (*Center) RegistEvent ¶
RegistEvent 注册事件
func (*Center) Subscribe ¶
func (p *Center) Subscribe(eventName string, fn func(...interface{})) ( *Subscriber, errors.ErrCode)
Subscribe 监听
func (*Center) Unsubscribe ¶
Unsubscribe 取消监听
func (*Center) UnsubscribeAll ¶
UnsubscribeAll 取消全部监听
type Predicate ¶
type Predicate func(evt interface{}, sub *Subscriber) bool
Predicate is a function used to filter messages before being forwarded to a subscriber
type Subscriber ¶
type Subscriber struct {
// contains filtered or unexported fields
}
Subscriber is returned from the Subscribe function.
This value and can be passed to Unsubscribe when the observer is no longer interested in receiving messages
func Subscribe ¶
func Subscribe(eventName string, fn func(...interface{})) (*Subscriber, errors.ErrCode)
Subscribe 监听
func (*Subscriber) WithPredicate ¶
func (p *Subscriber) WithPredicate(predicate Predicate) *Subscriber
WithPredicate sets a predicate to filter messages passed to the subscriber
type SubscriberGroup ¶
type SubscriberGroup struct {
// contains filtered or unexported fields
}
SubscriberGroup xxx
func (*SubscriberGroup) ClearSubscribers ¶
func (p *SubscriberGroup) ClearSubscribers()
ClearSubscribers 全部清理
func (*SubscriberGroup) Publish ¶
func (p *SubscriberGroup) Publish(values ...interface{})
Publish 发布消息
func (*SubscriberGroup) RemoveSubscriber ¶
func (p *SubscriberGroup) RemoveSubscriber(ids ...string) errors.ErrCode
RemoveSubscriber xxx
func (*SubscriberGroup) Subscriber ¶
func (p *SubscriberGroup) Subscriber(fn func(...interface{})) (*Subscriber, errors.ErrCode)
Subscriber xxx
Click to show internal directories.
Click to hide internal directories.