event

package module
v0.0.0-...-21ac4c2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2019 License: GPL-3.0 Imports: 3 Imported by: 1

README

event

event bus

Documentation

Index

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

func ListEvents

func ListEvents() (events []string)

ListEvents 全部事件

func Publish

func Publish(eventName string, event ...interface{})

Publish 发布消息

func RegistEvent

func RegistEvent(eventNames ...string) errors.ErrCode

RegistEvent 注册事件

func Unsubscribe

func Unsubscribe(eventName string, ids ...string) errors.ErrCode

Unsubscribe 取消监听

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

func NewEventCenter

func NewEventCenter(name string) Bus

NewEventCenter xxx

type Center

type Center struct {
	// contains filtered or unexported fields
}

Center xxx

func (*Center) ListEvents

func (p *Center) ListEvents() (events []string)

ListEvents 全部事件

func (*Center) Name

func (p *Center) Name() string

Name center name

func (*Center) Publish

func (p *Center) Publish(eventName string, evts ...interface{})

Publish 分发

func (*Center) RegistEvent

func (p *Center) RegistEvent(eventNames ...string) errors.ErrCode

RegistEvent 注册事件

func (*Center) Subscribe

func (p *Center) Subscribe(eventName string, fn func(...interface{})) (
	*Subscriber, errors.ErrCode)

Subscribe 监听

func (*Center) Unsubscribe

func (p *Center) Unsubscribe(eventName string, ids ...string) errors.ErrCode

Unsubscribe 取消监听

func (*Center) UnsubscribeAll

func (p *Center) UnsubscribeAll(eventName string)

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) GetID

func (p *Subscriber) GetID() string

GetID return Subscriber's id

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 NewSubscriberGroup

func NewSubscriberGroup() *SubscriberGroup

NewSubscriberGroup 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL