func SetMaxListeners(n int) {
	defaultEmmiter.SetMaxListeners(n)
}
SetMaxListeners obviously this function allows the MaxListeners
to be decrease or increase. Set to zero for unlimited
package events
import (
	"log"
	"reflect"
	"sync"
	"sync/atomic"
)
const (
	Version = "0.0.2"
	DefaultMaxListeners = 0
	EnableWarning = false
)
type (
	EventName string
	Listener func(...interface{})
	Events map[EventName][]Listener
	EventEmmiter interface {
		AddListener(EventName, ...Listener)
		Emit(EventName, ...interface{})
		EventNames() []EventName
		GetMaxListeners() int
		ListenerCount(EventName) int
		Listeners(EventName) []Listener
		On(EventName, ...Listener)
		Once(EventName, ...Listener)
		RemoveAllListeners(EventName) bool
		RemoveListener(EventName, Listener) bool
		Clear()
		SetMaxListeners(int)
		Len() int
	}
	emmiter struct {
		maxListeners int
		evtListeners Events
		mu           sync.RWMutex
	}
)
func (e Events) CopyTo(emmiter EventEmmiter) {
	if e != nil && len(e) > 0 {
		for evt, listeners := range e {
			if len(listeners) > 0 {
				emmiter.AddListener(evt, listeners...)
			}
		}
	}
}
func New() EventEmmiter {
	return &emmiter{maxListeners: DefaultMaxListeners, evtListeners: Events{}}
}
var (
	_              EventEmmiter = &emmiter{}
	defaultEmmiter              = New()
)
func AddListener(evt EventName, listener ...Listener) {
	defaultEmmiter.AddListener(evt, listener...)
}
func (e *emmiter) AddListener(evt EventName, listener ...Listener) {
	if len(listener) == 0 {
		return
	}
	e.mu.Lock()
	defer e.mu.Unlock()
	if e.evtListeners == nil {
		e.evtListeners = Events{}
	}
	listeners := e.evtListeners[evt]
	if e.maxListeners > 0 && len(listeners) == e.maxListeners {
		if EnableWarning {
			log.Printf(`(events) warning: possible EventEmitter memory '
                    leak detected. %d listeners added. '
                    Use emitter.SetMaxListeners(n int) to increase limit.`, len(listeners))
		}
		return
	}
	if listeners == nil {
		listeners = make([]Listener, e.maxListeners)
	}
	e.evtListeners[evt] = append(listeners, listener...)
}
func Emit(evt EventName, data ...interface{}) {
	defaultEmmiter.Emit(evt, data...)
}
func (e *emmiter) Emit(evt EventName, data ...interface{}) {
	e.mu.RLock()
	defer e.mu.RUnlock()
	if e.evtListeners == nil {
		return  
	}
	if listeners := e.evtListeners[evt]; listeners != nil && len(listeners) > 0 {  
		for i := range listeners {
			l := listeners[i]
			if l != nil {
				l(data...)
			}
		}
	}
}
func EventNames() []EventName {
	return defaultEmmiter.EventNames()
}
func (e *emmiter) EventNames() []EventName {
	if e.evtListeners == nil || e.Len() == 0 {
		return nil
	}
	names := make([]EventName, e.Len(), e.Len())
	i := 0
	for k := range e.evtListeners {
		names[i] = k
		i++
	}
	return names
}
func GetMaxListeners() int {
	return defaultEmmiter.GetMaxListeners()
}
func (e *emmiter) GetMaxListeners() int {
	return e.maxListeners
}
func ListenerCount(evt EventName) int {
	return defaultEmmiter.ListenerCount(evt)
}
func (e *emmiter) ListenerCount(evt EventName) int {
	if e.evtListeners == nil {
		return 0
	}
	len := 0
	if evtListeners := e.evtListeners[evt]; evtListeners != nil {  
		for _, l := range evtListeners {
			if l == nil {
				continue
			}
			len++
		}
	}
	return len
}
func Listeners(evt EventName) []Listener {
	return defaultEmmiter.Listeners(evt)
}
func (e *emmiter) Listeners(evt EventName) []Listener {
	if e.evtListeners == nil {
		return nil
	}
	var listeners []Listener
	if evtListeners := e.evtListeners[evt]; evtListeners != nil {
		for _, l := range evtListeners {
			if l == nil {
				continue
			}
			listeners = append(listeners, l)
		}
		if len(listeners) > 0 {
			return listeners
		}
	}
	return nil
}
func On(evt EventName, listener ...Listener) {
	defaultEmmiter.On(evt, listener...)
}
func (e *emmiter) On(evt EventName, listener ...Listener) {
	e.AddListener(evt, listener...)
}
func Once(evt EventName, listener ...Listener) {
	defaultEmmiter.Once(evt, listener...)
}
type oneTimelistener struct {
	evt        EventName
	emitter    *emmiter
	listener   Listener
	fired      int32
	executeRef Listener
}
func (l *oneTimelistener) execute(vals ...interface{}) {
	if atomic.CompareAndSwapInt32(&l.fired, 0, 1) {
		l.listener(vals)
		go l.emitter.RemoveListener(l.evt, l.executeRef)
	}
}
func (e *emmiter) Once(evt EventName, listener ...Listener) {
	if len(listener) == 0 {
		return
	}
	var modifiedListeners []Listener
	for _, listener := range listener {
		oneTime := &oneTimelistener{
			evt:      evt,
			emitter:  e,
			listener: listener,
		}
		oneTime.executeRef = oneTime.execute
		modifiedListeners = append(modifiedListeners, oneTime.executeRef)
	}
	e.AddListener(evt, modifiedListeners...)
}
func RemoveAllListeners(evt EventName) bool {
	return defaultEmmiter.RemoveAllListeners(evt)
}
func (e *emmiter) RemoveAllListeners(evt EventName) bool {
	if e.evtListeners == nil {
		return false  
	}
	e.mu.Lock()
	defer e.mu.Unlock()
	if listeners := e.evtListeners[evt]; listeners != nil {
		l := e.ListenerCount(evt)  
		delete(e.evtListeners, evt)
		if l > 0 {
			return true
		}
	}
	return false
}
func (e *emmiter) RemoveListener(evt EventName, listener Listener) bool {
	if e.evtListeners == nil {
		return false
	}
	if listener == nil {
		return false
	}
	e.mu.Lock()
	defer e.mu.Unlock()
	listeners := e.evtListeners[evt]
	if listeners == nil {
		return false
	}
	idx := -1
	listenerPointer := reflect.ValueOf(listener).Pointer()
	for index, item := range listeners {
		itemPointer := reflect.ValueOf(item).Pointer()
		if itemPointer == listenerPointer {
			idx = index
			break
		}
	}
	if idx < 0 {
		return false
	}
	var modifiedListeners []Listener = nil
	if len(listeners) > 1 {
		modifiedListeners = append(listeners[:idx], listeners[idx+1:]...)
	}
	e.evtListeners[evt] = modifiedListeners
	return true
}
func Clear() {
	defaultEmmiter.Clear()
}
func (e *emmiter) Clear() {
	e.evtListeners = Events{}
}