func Once(evt EventName, listener ...Listener) {
  defaultEmitter.Once(evt, listener...)
}
Once adds a one time listener function for the event named eventName.
The next time eventName is triggered, this listener is removed and then invoked.
package events
import (
  "log"
  "reflect"
  "sync"
)
const (
  DefaultMaxListeners = 0
  EnableWarning = false
)
type (
  EventName interface{}
  Listener func(...interface{})
  Events map[EventName][]Listener
  EventEmitter 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
  }
  emitter struct {
    maxListeners int
    evtListeners Events
    mu           sync.Mutex
  }
)
func (e Events) CopyTo(emitter EventEmitter) {
  if e != nil && len(e) > 0 {
    for evt, listeners := range e {
      if len(listeners) > 0 {
        emitter.AddListener(evt, listeners...)
      }
    }
  }
}
func New() EventEmitter {
  return &emitter{maxListeners: DefaultMaxListeners, evtListeners: Events{}}
}
var (
  _              EventEmitter = &emitter{}
  defaultEmitter              = New()
)
func AddListener(evt EventName, listener ...Listener) {
  defaultEmitter.AddListener(evt, listener...)
}
func (e *emitter) 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{}) {
  defaultEmitter.Emit(evt, data...)
}
func (e *emitter) Emit(evt EventName, data ...interface{}) {
  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 defaultEmitter.EventNames()
}
func (e *emitter) 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 defaultEmitter.GetMaxListeners()
}
func (e *emitter) GetMaxListeners() int {
  return e.maxListeners
}
func ListenerCount(evt EventName) int {
  return defaultEmitter.ListenerCount(evt)
}
func (e *emitter) ListenerCount(evt EventName) int {
  if e.evtListeners == nil {
    return 0
  }
  length := 0
  if evtListeners := e.evtListeners[evt]; evtListeners != nil {  
    for _, l := range evtListeners {
      if l == nil {
        continue
      }
      length++
    }
  }
  return length
}
func Listeners(evt EventName) []Listener {
  return defaultEmitter.Listeners(evt)
}
func (e *emitter) 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) {
  defaultEmitter.On(evt, listener...)
}
func (e *emitter) On(evt EventName, listener ...Listener) {
  e.AddListener(evt, listener...)
}