Skip to content
Newer
Older
100644 30 lines (23 sloc) 539 Bytes
5ec06f2 @mloughran Use EventMachine rather than EM in module names
authored
1 module EventMachine::Hiredis
710660b @mloughran Initial functioning code extracted from pusherapp
authored
2 module EventEmitter
3 def on(event, &listener)
4 _listeners[event] << listener
5 end
6
7 def emit(event, *args)
8 _listeners[event].each { |l| l.call(*args) }
9 end
10
11 def remove_listener(event, &listener)
12 _listeners[event].delete(listener)
13 end
14
15 def remove_all_listeners(event)
16 _listeners.delete(event)
17 end
18
19 def listeners(event)
20 _listeners[event]
21 end
22
23 private
24
25 def _listeners
26 @_listeners ||= Hash.new { |h,k| h[k] = [] }
27 end
28 end
29 end
Something went wrong with that request. Please try again.