Class: XRBP::WebSocket::Message

Inherits:
Object
  • Object
show all
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

Command

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#blObject



36
37
38
39
40
41
# File 'lib/xrbp/websocket/message.rb', line 36

def bl
  @bl ||= proc { |res|
    @result = res
    signal
  }
end

#connectionObject

Returns the value of attribute connection.



7
8
9
# File 'lib/xrbp/websocket/message.rb', line 7

def connection
  @connection
end

#resultObject (readonly)

Returns the value of attribute result.



6
7
8
# File 'lib/xrbp/websocket/message.rb', line 6

def result
  @result
end

#timeObject

Returns the value of attribute time.



7
8
9
# File 'lib/xrbp/websocket/message.rb', line 7

def time
  @time
end

Instance Method Details

#signalObject



21
22
23
24
25
# File 'lib/xrbp/websocket/message.rb', line 21

def signal
  @signalled = true
  @cv.signal
  self
end

#to_sObject



17
18
19
# File 'lib/xrbp/websocket/message.rb', line 17

def to_s
  @data
end

#waitObject



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