Documentation ¶
Overview ¶
Package eventbus provides a simple event system that can be used synchronous and asynchronous using channels and callbacks. It also supports subscribing via wildcards to listen to a group/unit of event channels
Index ¶
- type CallbackFunc
- type Event
- type EventBus
- func (eb *EventBus) HasSubscribers(topic string) bool
- func (eb *EventBus) Publish(topic string, data interface{}) interface{}
- func (eb *EventBus) PublishAsync(topic string, data interface{})
- func (eb *EventBus) PublishAsyncOnce(topic string, data interface{})
- func (eb *EventBus) PublishOnce(topic string, data interface{}) interface{}
- func (eb *EventBus) Stats() *Stats
- func (eb *EventBus) Subscribe(topic string) EventChannel
- func (eb *EventBus) SubscribeCallback(topic string, callable CallbackFunc)
- func (eb *EventBus) SubscribeChannel(topic string, ch EventChannel)
- type EventChannel
- type SafeCounter
- type Stats
- type TopicStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallbackFunc ¶
type CallbackFunc func(topic string, data interface{})
CallbackFunc Defines a CallbackFunc.
type Event ¶
type Event struct { Data interface{} Topic string // contains filtered or unexported fields }
Event holds topic name and data.
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus stores the information about subscribers interested for a particular topic.
func (*EventBus) HasSubscribers ¶
HasSubscribers Check if a topic has subscribers.
func (*EventBus) Publish ¶
Publish data to a topic and wait for all subscribers to finish This function creates a waitGroup internally. All subscribers must call Done() function on Event.
func (*EventBus) PublishAsync ¶
PublishAsync data to a topic asynchronously This function returns a bool channel which indicates that all subscribers where called.
func (*EventBus) PublishAsyncOnce ¶
PublishAsyncOnce same as PublishAsync but makes sure that topic is only published once.
func (*EventBus) PublishOnce ¶
PublishOnce same as Publish but makes sure only published once on topic.
func (*EventBus) Subscribe ¶
func (eb *EventBus) Subscribe(topic string) EventChannel
Subscribe to a topic passing a EventChannel.
func (*EventBus) SubscribeCallback ¶
func (eb *EventBus) SubscribeCallback(topic string, callable CallbackFunc)
SubscribeCallback provides a simple wrapper that allows to directly register CallbackFunc instead of channels.
func (*EventBus) SubscribeChannel ¶
func (eb *EventBus) SubscribeChannel(topic string, ch EventChannel)
SubscribeChannel subscribes to a given Channel.
type EventChannel ¶
type EventChannel chan Event
EventChannel is a channel which can accept an Event.
func NewEventChannel ¶
func NewEventChannel() EventChannel
NewEventChannel Creates a new EventChannel.
type SafeCounter ¶
type SafeCounter struct {
// contains filtered or unexported fields
}
SafeCounter is a concurrency safe counter.
func (*SafeCounter) DecBy ¶
func (c *SafeCounter) DecBy(dec uint)
DecBy decrements the counter by given delta.
func (*SafeCounter) IncBy ¶
func (c *SafeCounter) IncBy(add uint)
IncBy increments the counter by given delta.
type Stats ¶
type Stats struct {
// contains filtered or unexported fields
}
func (*Stats) GetPublishedCountByTopic ¶
func (*Stats) GetSubscriberCountByTopic ¶
func (*Stats) GetTopicStats ¶
func (s *Stats) GetTopicStats() []*TopicStats
func (*Stats) GetTopicStatsByName ¶
func (s *Stats) GetTopicStatsByName(topicName string) *TopicStats
type TopicStats ¶
type TopicStats struct { Name string PublishedCount *SafeCounter SubscriberCount *SafeCounter }