Class: Messed::Util::RemoteStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/messed/util/remote_status.rb

Defined Under Namespace

Classes: StatusHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ RemoteStatus

Returns a new instance of RemoteStatus.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/messed/util/remote_status.rb', line 24

def initialize(host, port)
  host ||= '127.0.0.1'
  @status = {}
  EM.run do
    EM.add_timer(5) {
      @status['error'] = "timeout on connect"
      EM.stop_event_loop
    }
    begin
      EM.connect(host, port, StatusHandler) do |handler|
        handler.status = @status
      end
    rescue
      @status['error'] = "can't connect"
      EM.stop_event_loop
    end
  end
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/messed/util/remote_status.rb', line 5

def status
  @status
end