Class: XRBP::WebSocket::Message
- Inherits:
-
Object
- Object
- XRBP::WebSocket::Message
- Defined in:
- lib/xrbp/websocket/message.rb
Overview
Raw data which to write to websocket and mechanisms which to track and manage response state.
Direct Known Subclasses
Instance Attribute Summary collapse
- #bl ⇒ Object
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
-
#initialize(data) ⇒ Message
constructor
A new instance of Message.
- #signal ⇒ Object
- #to_s ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(data) ⇒ Message
Returns a new instance of Message.
9 10 11 12 13 14 15 |
# File 'lib/xrbp/websocket/message.rb', line 9 def initialize(data) @data = data @result = nil @cv = ConditionVariable.new @signalled = false @time = Time.now end |
Instance Attribute Details
#bl ⇒ Object
36 37 38 39 40 41 |
# File 'lib/xrbp/websocket/message.rb', line 36 def bl @bl ||= proc { |res| @result = res signal } end |
#connection ⇒ Object
Returns the value of attribute connection.
7 8 9 |
# File 'lib/xrbp/websocket/message.rb', line 7 def connection @connection end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/xrbp/websocket/message.rb', line 6 def result @result end |
#time ⇒ Object
Returns the value of attribute time.
7 8 9 |
# File 'lib/xrbp/websocket/message.rb', line 7 def time @time end |
Instance Method Details
#signal ⇒ Object
21 22 23 24 25 |
# File 'lib/xrbp/websocket/message.rb', line 21 def signal @signalled = true @cv.signal self end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/xrbp/websocket/message.rb', line 17 def to_s @data end |
#wait ⇒ Object
27 28 29 30 31 32 |
# File 'lib/xrbp/websocket/message.rb', line 27 def wait connection.state_mutex.synchronize { # only wait if we haven't received response @cv.wait(connection.state_mutex) unless connection.closed? || @signalled } end |