Class: OBS::WebSocket::EventDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/obs/websocket.rb

Instance Method Summary collapse

Constructor Details

#initializeEventDispatcher

Returns a new instance of EventDispatcher.



147
148
149
# File 'lib/obs/websocket.rb', line 147

def initialize
  @listeners = Hash.new {|h, k| h[k] = []}
end

Instance Method Details

#dispatch(update_type, payload) ⇒ Object



155
156
157
158
159
160
# File 'lib/obs/websocket.rb', line 155

def dispatch(update_type, payload)
  event = Protocol::Event.create(update_type, payload).freeze
  @listeners[update_type].each do |(executor, listener)|
    Concurrent::Promises.future_on(executor, event, &listener).run
  end
end

#register(executor, type, listener) ⇒ Object



151
152
153
# File 'lib/obs/websocket.rb', line 151

def register(executor, type, listener)
  @listeners[type].push([executor, listener])
end