Documentation ¶
Index ¶
- type DispatchMap
- func (m *DispatchMap) Access(key int32) (*SubscriberMap, bool)
- func (m *DispatchMap) AccessOrInit(key int32, value *SubscriberMap) (*SubscriberMap, bool)
- func (m *DispatchMap) Iterate(itfunc func(int32, *SubscriberMap) bool)
- func (m *DispatchMap) Remove(key int32)
- func (m *DispatchMap) SetValue(key int32, value *SubscriberMap)
- type Event
- type EventBus
- func (evbus *EventBus) Finalize()
- func (evbus *EventBus) GetEventTypeId(typename string) (int32, error)
- func (evbus *EventBus) PublishEvent(event Event) error
- func (evbus *EventBus) RegisterEventType(typename string) (int32, error)
- func (evbus *EventBus) Subscribe(sb Subscriber) int
- func (evbus *EventBus) Unsubscribe(sbid int) error
- type EventTypeMap
- type Subscriber
- type SubscriberMap
- func (m *SubscriberMap) Access(key int32) (Subscriber, bool)
- func (m *SubscriberMap) AccessOrInit(key int32, value Subscriber) (Subscriber, bool)
- func (m *SubscriberMap) Iterate(itfunc func(int32, Subscriber) bool)
- func (m *SubscriberMap) Remove(key int32)
- func (m *SubscriberMap) SetValue(key int32, value Subscriber)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DispatchMap ¶
DispatchMap is the shortcut when bus need to dispatch every event. Mapping is event type id(int) -> subscriber map(*SubscriberMap)
func (*DispatchMap) Access ¶
func (m *DispatchMap) Access(key int32) (*SubscriberMap, bool)
Access the event type map.
func (*DispatchMap) AccessOrInit ¶
func (m *DispatchMap) AccessOrInit(key int32, value *SubscriberMap) (*SubscriberMap, bool)
AccessOrInit explains itself, return false on initialized
func (*DispatchMap) Iterate ¶
func (m *DispatchMap) Iterate(itfunc func(int32, *SubscriberMap) bool)
Iterate requires you to read sync.Map.Range
func (*DispatchMap) Remove ¶
func (m *DispatchMap) Remove(key int32)
Remove the given key from the map.
func (*DispatchMap) SetValue ¶
func (m *DispatchMap) SetValue(key int32, value *SubscriberMap)
SetValue setup the mapping
type Event ¶
type Event struct { EventId uint32 // a no type event will only dispatch to wildcard subscribers. EventType []int EventTime time.Time Payload interface{} }
Event represents each individual event
type EventBus ¶
type EventBus struct { Events sync.Pool EventCounter uint32 PendingCounter uint32 PendingThreshold uint32 Subscribers *SubscriberMap WildcardSubscribers *SubscriberMap SubscriberCounter int32 DispatchList *DispatchMap EventTypeList *EventTypeMap EventTypeCounter int32 EachEventBackfileBase time.Duration EachEventBackfireThresh time.Duration EventLoopBackfireBase time.Duration EventLoopBackfireThresh time.Duration // contains filtered or unexported fields }
EventBus is a bus for events dispatched to it.
func (*EventBus) Finalize ¶
func (evbus *EventBus) Finalize()
Finalize stops the event dispatching process after that, dont use it!
func (*EventBus) GetEventTypeId ¶
GetEventTypeId doesn't need to be access from outside
func (*EventBus) PublishEvent ¶
PublishEvent will ignore the event id in parameter.
func (*EventBus) RegisterEventType ¶
RegisterEventType register the given name, and return the event type id on succeed.
func (*EventBus) Subscribe ¶
func (evbus *EventBus) Subscribe(sb Subscriber) int
Subscribe to some events. parameter sb.id will be ignored and the returned integer will be the final IDs.
func (*EventBus) Unsubscribe ¶
Unsubscribe to events. The sbid must be provided.
type EventTypeMap ¶
EventTypeMap is the map of name(string) -> event type id(int32)
func (*EventTypeMap) Access ¶
func (m *EventTypeMap) Access(key string) (int32, bool)
Access the event type map.
func (*EventTypeMap) AccessOrInit ¶
func (m *EventTypeMap) AccessOrInit(key string, value int32) (int32, bool)
AccessOrInit explains itself, return false on initialized
func (*EventTypeMap) Iterate ¶
func (m *EventTypeMap) Iterate(itfunc func(string, int32) bool)
Iterate requires you to read sync.Map.Range
func (*EventTypeMap) Remove ¶
func (m *EventTypeMap) Remove(key string)
Remove the given key from the map.
func (*EventTypeMap) SetValue ¶
func (m *EventTypeMap) SetValue(key string, value int32)
SetValue setup the mapping
type Subscriber ¶
type Subscriber struct { SubscriberId int // Priority ranged from -999 ~ 999. SubscriberPriority int // Not subscribing anything means subscribing everything. // Keep that in mind.. SubscribedTypes []int MessageChannel chan Event // The bool value returned in this functor will determine // whether this event is consumed, preventing further subscribers // to receive it. true -> consumed // Anyway, an event will be consumed after iterating through every subscribers resulted in // any matching subscriber found. // Warning: dont run time-consuming stuff in it, return as soon as possible! MessageFunctor func(Subscriber, Event) bool Extra interface{} }
Subscriber is entities listening on the event bus
type SubscriberMap ¶
SubscriberMap is the map of subscriber id(int) -> subscriber(Subscriber)
func NewSubscriberMap ¶
func NewSubscriberMap() *SubscriberMap
NewSubscriberMap creates a new instance.
func (*SubscriberMap) Access ¶
func (m *SubscriberMap) Access(key int32) (Subscriber, bool)
Access the event type map.
func (*SubscriberMap) AccessOrInit ¶
func (m *SubscriberMap) AccessOrInit(key int32, value Subscriber) (Subscriber, bool)
AccessOrInit explains itself, return false on initialized
func (*SubscriberMap) Iterate ¶
func (m *SubscriberMap) Iterate(itfunc func(int32, Subscriber) bool)
Iterate requires you to read sync.Map.Range
func (*SubscriberMap) Remove ¶
func (m *SubscriberMap) Remove(key int32)
Remove the given key from the map.
func (*SubscriberMap) SetValue ¶
func (m *SubscriberMap) SetValue(key int32, value Subscriber)
SetValue setup the mapping