Thank you! Works great: 
    
    
    import tables
    
    type EventEmitter = ref object
      eventsMap: Table[string, seq[proc(event: string)]]
    
    proc subscribe(emitter: EventEmitter, event: string, callback: proc(event: 
string)) =
      if not emitter.eventsMap.hasKey(event):
        emitter.eventsMap[event] = @[]
      emitter.eventsMap[event].add(callback)
    
    proc emit(emitter: EventEmitter, event: string) =
      if not emitter.eventsMap.hasKey(event): return
      for callback in emitter.eventsMap[event]:
        callback(event)
    
    
    Run

Reply via email to