def send_command(options, verbose=false, timeout=20, &handler)
      return if @closing
      @last_timeout = timeout
      manage_em = !EM.reactor_running?
      response_handler = lambda do
        EM.stop if manage_em
        handler.call(@response) if handler && @response
        @pending -= 1
        @close_handler.call if @close_handler && @pending == 0
      end
      send_handler = lambda do
        @pending += 1
        command = options.dup
        command[:verbose] = verbose
        command[:timeout] = timeout
        command[:cookie] = @cookie
        EM.next_tick { EM.connect('127.0.0.1', @socket_port, ConnectionHandler, command, self, response_handler) }
        EM.add_timer(timeout) { EM.stop; raise 'Timed out waiting for agent reply' } if manage_em
      end
      if manage_em
        EM.run { send_handler.call }
      else
        send_handler.call
      end
      true
    end
def send_command(options, verbose=false, timeout=20, &handler)
      return if @closing
      @last_timeout = timeout
      manage_em = !EM.reactor_running?
      response_handler = lambda do
        EM.stop if manage_em
        handler.call(@response) if handler && @response
        @pending -= 1
        @close_handler.call if @close_handler && @pending == 0
      end
      send_handler = lambda do
        @pending += 1
        command = options.dup
        command[:verbose] = verbose
        command[:timeout] = timeout
        command[:cookie] = @cookie
        EM.next_tick { EM.connect('127.0.0.1', @socket_port, ConnectionHandler, command, self, response_handler) }
        EM.add_timer(timeout) { EM.stop; raise 'Timed out waiting for agent reply' } if manage_em
      end
      if manage_em
        EM.run { send_handler.call }
      else
        send_handler.call
      end
      true
    end
Send command to running agent

 === Parameters
 options(Hash):: Hash of options and command name
   options[:name]:: Command name
   options[:...]:: Other command specific options, passed through to agent
 verbose(Boolean):: Whether client should display debug info
 timeout(Integer):: Number of seconds we should wait for a reply from the agent

 === Block
 handler: Command results handler

 === Return
 true:: Always return true

 === Raise
 RuntimeError:: Timed out waiting for result, raised in EM thread