Class: OBS::WebSocket::ResponseDispatcher
- Inherits:
-
Object
- Object
- OBS::WebSocket::ResponseDispatcher
- Defined in:
- lib/obs/websocket.rb
Instance Method Summary collapse
- #dispatch(message_id, payload) ⇒ Object
-
#initialize ⇒ ResponseDispatcher
constructor
A new instance of ResponseDispatcher.
- #register(executor, request) ⇒ Object
Constructor Details
#initialize ⇒ ResponseDispatcher
Returns a new instance of ResponseDispatcher.
164 165 166 |
# File 'lib/obs/websocket.rb', line 164 def initialize @ongoing_requests = {} end |
Instance Method Details
#dispatch(message_id, payload) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/obs/websocket.rb', line 180 def dispatch(, payload) if h = @ongoing_requests.delete() request = h[:request] future = h[:future] case payload['status'] when 'ok' response_class = request.class.const_get(:Response) future.fulfill(response_class.new(payload)) when 'error' future.reject(RequestError.new(payload['error'])) else fail 'Unknown status' end end end |
#register(executor, request) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/obs/websocket.rb', line 168 def register(executor, request) = future = Concurrent::Promises.resolvable_future_on(executor) @ongoing_requests[] = { request: request, future: future, } [, future.with_hidden_resolvable] end |