Documentation
¶
Index ¶
- type ArgumentProcessor
- type Bus
- type BusController
- type BusPublisher
- type BusSubscriber
- type EventBus
- func (bus *EventBus) HasCallback(topic string) bool
- func (bus *EventBus) Publish(topic string, args ...any)
- func (bus *EventBus) SetArgumentProcessor(topic string, argProc ArgumentProcessor)
- func (bus *EventBus) SetDefaultArgumentProcessor(argProc ...ArgumentProcessor)
- func (bus *EventBus) Subscribe(topic string, fn any) error
- func (bus *EventBus) SubscribeAsync(topic string, fn any, transactional bool) error
- func (bus *EventBus) SubscribeOnce(topic string, fn any) error
- func (bus *EventBus) SubscribeOnceAsync(topic string, fn any) error
- func (bus *EventBus) Unsubscribe(topic string, handler any) error
- func (bus *EventBus) WaitAsync()
- type EventHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArgumentProcessor ¶ added in v1.1.0
type ArgumentProcessor = func(callback *EventHandler, arg ...any) []reflect.Value
type Bus ¶
type Bus interface { BusController BusSubscriber BusPublisher }
Bus englobes global (subscribe, publish, control) bus behavior
type BusController ¶
BusController defines bus control behavior (checking handler's presence, synchronization)
type BusPublisher ¶
BusPublisher defines publishing-related bus behavior
type BusSubscriber ¶
type BusSubscriber interface { Subscribe(topic string, fn any) error SubscribeAsync(topic string, fn any, transactional bool) error SubscribeOnce(topic string, fn any) error SubscribeOnceAsync(topic string, fn any) error Unsubscribe(topic string, handler any) error SetArgumentProcessor(topic string, argProc ArgumentProcessor) SetDefaultArgumentProcessor(argProc ...ArgumentProcessor) }
BusSubscriber defines subscription-related bus behavior
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus - box for handlers and callbacks.
func (*EventBus) HasCallback ¶
HasCallback returns true if exists any callback subscribed to the topic.
func (*EventBus) Publish ¶
Publish executes callback defined for a topic. Any additional argument will be transferred to the callback.
func (*EventBus) SetArgumentProcessor ¶ added in v1.1.0
func (bus *EventBus) SetArgumentProcessor(topic string, argProc ArgumentProcessor)
SetArgumentProcessor sets the argument processor for a topic
The argument processor is useful for customizing how arguments are passed to the subscriber's callback. The default argument processor will be used if no argument processor is set for a topic.
func (*EventBus) SetDefaultArgumentProcessor ¶ added in v1.2.0
func (bus *EventBus) SetDefaultArgumentProcessor(argProc ...ArgumentProcessor)
SetDefaultArgumentProcessor sets the default argument processor
Pass no arguments to reset the default argument processor to the built-in default argument processor.
func (*EventBus) Subscribe ¶
Subscribe subscribes to a topic. Returns error if `fn` is not a function.
func (*EventBus) SubscribeAsync ¶
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 ¶
SubscribeOnce subscribes to a topic once. Handler will be removed after executing. Returns error if `fn` is not a function.
func (*EventBus) SubscribeOnceAsync ¶
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 ¶
Unsubscribe removes callback defined for a topic. Returns error if there are no callbacks subscribed to the topic.