Documentation ¶
Index ¶
- Constants
- Variables
- type Emitter
- func (emitter *Emitter) AddListener(event, listener interface{}) *Emitter
- func (emitter *Emitter) Emit(event interface{}, arguments ...interface{}) *Emitter
- func (emitter *Emitter) GetListenerCount(event interface{}) (count int)
- func (emitter *Emitter) Off(event, listener interface{}) *Emitter
- func (emitter *Emitter) On(event, listener interface{}) *Emitter
- func (emitter *Emitter) Once(event, listener interface{}) *Emitter
- func (emitter *Emitter) RecoverWith(listener RecoveryListener) *Emitter
- func (emitter *Emitter) RemoveListener(event, listener interface{}) *Emitter
- func (emitter *Emitter) SetMaxListeners(max int) *Emitter
- type RecoveryListener
Constants ¶
const DefaultMaxListeners = 10
Default number of maximum listeners for an event.
Variables ¶
var ErrNoneFunction = errors.New("Kind of Value for listener is not Func.")
Error presented when an invalid argument is provided as a listener function
Functions ¶
This section is empty.
Types ¶
type Emitter ¶
type Emitter struct { // Mutex to prevent race conditions within the Emitter. *sync.Mutex // contains filtered or unexported fields }
Emitter ...
func NewEmitter ¶
func NewEmitter() (emitter *Emitter)
NewEmitter returns a new Emitter object, defaulting the number of maximum listeners per event to the DefaultMaxListeners constant and initializing its events map.
func (*Emitter) AddListener ¶
AddListener appends the listener argument to the event arguments slice in the Emitter's events map. If the number of listeners for an event is greater than the Emitter's maximum listeners then a warning is printed. If the relect Value of the listener does not have a Kind of Func then AddListener panics. If a RecoveryListener has been set then it is called recovering from the panic.
func (*Emitter) Emit ¶
Emit attempts to use the reflect package to Call each listener stored in the Emitter's events map with the supplied arguments. Each listener is called within its own go routine. The reflect package will panic if the agruments supplied do not align the parameters of a listener function. If a RecoveryListener has been set then it is called after recovering from the panic.
func (*Emitter) GetListenerCount ¶
GetListenerCount gets count of listeners for a given event.
func (*Emitter) Once ¶
Once generates a new function which invokes the supplied listener only once before removing itself from the event's listener slice in the Emitter's events map. If the reflect Value of the listener does not have a Kind of Func then Once panics. If a RecoveryListener has been set then it is called after recovering from the panic.
func (*Emitter) RecoverWith ¶
func (emitter *Emitter) RecoverWith(listener RecoveryListener) *Emitter
RecoverWith sets the listener to call when a panic occurs, recovering from panics and attempting to keep the application from crashing.
func (*Emitter) RemoveListener ¶
RemoveListener removes the listener argument from the event arguments slice in the Emitter's events map. If the reflect Value of the listener does not have a Kind of Func then RemoveListener panics. If a RecoveryListener has been set then it is called after recovering from the panic.
func (*Emitter) SetMaxListeners ¶
SetMaxListeners sets the maximum number of listeners per event for the Emitter. If -1 is passed as the maximum, all events may have unlimited listeners. By default, each event can have a maximum number of 10 listeners which is useful for finding memory leaks.
type RecoveryListener ¶
type RecoveryListener func(interface{}, interface{}, error)
RecoveryListener ...