Class: Bixby::WebSocket::AsyncResponse
- Inherits:
-
Object
- Object
- Bixby::WebSocket::AsyncResponse
- Defined in:
- lib/bixby-common/websocket/async_response.rb
Overview
Asynchronously receive a response via WebSocket channel
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#completed? ⇒ Boolean
Has the request completed?.
-
#initialize(id) ⇒ AsyncResponse
constructor
A new instance of AsyncResponse.
-
#response ⇒ Object
Retrieve the response, blocking until it is available.
-
#response=(obj) ⇒ Object
Set the response and signal any blocking threads.
Constructor Details
#initialize(id) ⇒ AsyncResponse
Returns a new instance of AsyncResponse.
12 13 14 15 16 17 18 |
# File 'lib/bixby-common/websocket/async_response.rb', line 12 def initialize(id) @id = id @mutex = Mutex.new @cond = ConditionVariable.new @response = nil @completed = false end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/bixby-common/websocket/async_response.rb', line 10 def id @id end |
Instance Method Details
#completed? ⇒ Boolean
Has the request completed?
34 35 36 |
# File 'lib/bixby-common/websocket/async_response.rb', line 34 def completed? @completed end |
#response ⇒ Object
Retrieve the response, blocking until it is available
41 42 43 44 45 |
# File 'lib/bixby-common/websocket/async_response.rb', line 41 def response return @response if @completed @mutex.synchronize { @cond.wait(@mutex) } return @response end |
#response=(obj) ⇒ Object
Set the response and signal any blocking threads
23 24 25 26 27 28 29 |
# File 'lib/bixby-common/websocket/async_response.rb', line 23 def response=(obj) @mutex.synchronize { @completed = true @response = obj @cond.signal } end |