Documentation
¶
Index ¶
- Constants
- func Dispatch[T EventInterface](event T, strategy ProcessingStrategy) []error
- func DispatchConcurrent[T EventInterface](event T) []error
- func DispatchConcurrentPerPriority[T EventInterface](event T) []error
- func DispatchSequential[T EventInterface](event T) []error
- func Subscribe[T EventInterface](name string, action func(T) error) interface{}
- func SubscribeWithPriority[T EventInterface](name string, action func(T) error, priority int) interface{}
- func Unsubscribe(sub interface{})
- type EventDispatcher
- func (e *EventDispatcher[T]) Dispatch(event T, processingStrategy ProcessingStrategy) []error
- func (e *EventDispatcher[T]) Subscribe(name string, action func(T) error) Subscriber[T]
- func (e *EventDispatcher[T]) SubscribeWithPriority(name string, action func(T) error, priority int) interface{}
- func (e *EventDispatcher[T]) Unsubscribe(rawSub interface{})
- type EventInterface
- type ProcessingStrategy
- type Subscriber
Constants ¶
const ( HighPriority = 100 //NormalPriority default priority NormalPriority = 0 LowPriority = -100 //Sequential runs every action sequentially. Sequential ProcessingStrategy = iota //Concurrent runs every action at once, regardless priority Concurrent //PerPriorityConcurrent runs every actions concurrently regarding every priority. The priority processing is sequential. PerPriorityConcurrent )
Variables ¶
This section is empty.
Functions ¶
func Dispatch ¶
func Dispatch[T EventInterface](event T, strategy ProcessingStrategy) []error
Dispatch sends an event to every same name events. Processing Strategies are defined for concurrency/sequential behaviors.
func DispatchConcurrent ¶
func DispatchConcurrent[T EventInterface](event T) []error
func DispatchConcurrentPerPriority ¶
func DispatchConcurrentPerPriority[T EventInterface](event T) []error
DispatchConcurrentPerPriority processes every priority sequentially, but with concurrent working in the tasks.
func DispatchSequential ¶
func DispatchSequential[T EventInterface](event T) []error
DispatchSequential sends an event through every action in a sequential mode.
func Subscribe ¶
func Subscribe[T EventInterface](name string, action func(T) error) interface{}
Subscribe attach an action to an event name given. Internally, this function, will attach the action to a normalPriority (0)
func SubscribeWithPriority ¶
func SubscribeWithPriority[T EventInterface](name string, action func(T) error, priority int) interface{}
SubscribeWithPriority attach an action to an event name given and weights the priority The higher the priority the first will the action be trigger.
func Unsubscribe ¶
func Unsubscribe(sub interface{})
Unsubscribe removes the subscription previously made.
Types ¶
type EventDispatcher ¶
type EventDispatcher[T EventInterface] struct { // contains filtered or unexported fields }
This structure contains a map of every events registered in the event Dispatcher
func NewDispatcher ¶
func NewDispatcher() EventDispatcher[EventInterface]
NewDispatcher creates a new eventDispatcher for EventInterfaces
func (*EventDispatcher[T]) Dispatch ¶
func (e *EventDispatcher[T]) Dispatch( event T, processingStrategy ProcessingStrategy, ) []error
Dispatch sends an event through every concerned event subscribers
func (*EventDispatcher[T]) Subscribe ¶
func (e *EventDispatcher[T]) Subscribe(name string, action func(T) error) Subscriber[T]
Subscribe attach an action to an event name given. Internally, this function, will attach the action to a normalPriority (0)
func (*EventDispatcher[T]) SubscribeWithPriority ¶
func (e *EventDispatcher[T]) SubscribeWithPriority(name string, action func(T) error, priority int) interface{}
SubscribeWithPriority attach an action to an event name given and weights the priority The higher the priority the first will the action be trigger.
func (*EventDispatcher[T]) Unsubscribe ¶
func (e *EventDispatcher[T]) Unsubscribe(rawSub interface{})
Unsubscribe removes the subscription previously made.
type EventInterface ¶
type EventInterface interface { //Name the name of the event Name() string }
EventInterface This interface is the "event enveloppe" for dispatching elements through all subscribes
type Subscriber ¶
type Subscriber[T EventInterface] struct { // contains filtered or unexported fields }