Documentation ¶
Index ¶
- type EventBus
- func (bus *EventBus) HasCallback(topic EventTopic) bool
- func (bus *EventBus) Publish(topic EventTopic, args ...interface{})
- func (bus *EventBus) Subscribe(topic EventTopic, fn interface{}) error
- func (bus *EventBus) SubscribeAsyncPool(topic EventTopic, fn interface{}, transactional bool) error
- func (bus *EventBus) SubscribeOnce(topic EventTopic, fn interface{}) error
- func (bus *EventBus) SubscribeOnceAsync(topic EventTopic, fn interface{}) error
- func (bus *EventBus) Unsubscribe(topic EventTopic, handler interface{}) error
- func (bus *EventBus) WaitAsync()
- type EventBusPublisher
- type EventBusSubscriber
- type EventTopic
- type Interface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus - box for handlers and callbacks.
func (*EventBus) HasCallback ¶
func (bus *EventBus) HasCallback(topic EventTopic) bool
HasCallback returns true if exists any callback subscribed to the topic.
func (*EventBus) Publish ¶
func (bus *EventBus) Publish(topic EventTopic, args ...interface{})
Publish executes callback defined for a topic. Any additional argument will be transferred to the callback.
func (*EventBus) Subscribe ¶
func (bus *EventBus) Subscribe(topic EventTopic, fn interface{}) error
Subscribe subscribes to a topic. Returns error if `fn` is not a function.
func (*EventBus) SubscribeAsyncPool ¶
func (bus *EventBus) SubscribeAsyncPool(topic EventTopic, fn interface{}, transactional bool) error
SubscribeAsync subscribes to a topic with an asynchronous callback Transactional determines whether subsequent callbacks for a topic are run serially (true) or concurrently (false) Returns error if `fn` is not a function.
func (*EventBus) SubscribeOnce ¶
func (bus *EventBus) SubscribeOnce(topic EventTopic, fn interface{}) error
SubscribeOnce subscribes to a topic once. Handler will be removed after executing. Returns error if `fn` is not a function.
func (*EventBus) SubscribeOnceAsync ¶
func (bus *EventBus) SubscribeOnceAsync(topic EventTopic, fn interface{}) error
SubscribeOnceAsync subscribes to a topic once with an asynchronous callback Handler will be removed after executing. Returns error if `fn` is not a function.
func (*EventBus) Unsubscribe ¶
func (bus *EventBus) Unsubscribe(topic EventTopic, handler interface{}) error
Unsubscribe removes callback defined for a topic. Returns error if there are no callbacks subscribed to the topic.
type EventBusPublisher ¶
type EventBusPublisher interface {
Publish(topic EventTopic, args ...interface{})
}
BusPublisher defines publishing-related bus behavior
type EventBusSubscriber ¶
type EventBusSubscriber interface { Subscribe(topic EventTopic, fn interface{}) error //transactional 为true,代表顺序化执行callback SubscribeAsyncPool(topic EventTopic, fn interface{}, transactional bool) error SubscribeOnce(topic EventTopic, fn interface{}) error SubscribeOnceAsync(topic EventTopic, fn interface{}) error Unsubscribe(topic EventTopic, handler interface{}) error }
EventBusSubscriber defines subscription-related bus behavior
type EventTopic ¶
type EventTopic string
type Interface ¶
type Interface interface { EventBusSubscriber EventBusPublisher HasCallback(topic EventTopic) bool WaitAsync() }
EventBus englobes global (subscribe, publish, control) bus behavior