def request(method, params, timeout: 30)
      if !wait_until("websocket client is connected", timeout: timeout, threshold: 10.0, interval: 0.1) { connected? }
        raise TimeoutError.new(500, 'WebsocketClient is not connected')
      end

      id = request_id
      observable = @requests[id] = RequestObservable.new(method, id)

      websocket_client.send_request(id, method, params)

      begin
        result, error = observe(observable, timeout: timeout)
      rescue Timeout::Error => exc
        raise TimeoutError.new(500, exc.message)
      end

      @requests.delete(id)

      if error
        raise Error.new(error['code'], error['message'])
      else
        return result
      end
    rescue => exc
      warn exc
      abort exc
    end
def request(method, params, timeout: 30)
      if !wait_until("websocket client is connected", timeout: timeout, threshold: 10.0, interval: 0.1) { connected? }
        raise TimeoutError.new(500, 'WebsocketClient is not connected')
      end

      id = request_id
      observable = @requests[id] = RequestObservable.new(method, id)

      websocket_client.send_request(id, method, params)

      begin
        result, error = observe(observable, timeout: timeout)
      rescue Timeout::Error => exc
        raise TimeoutError.new(500, exc.message)
      end

      @requests.delete(id)

      if error
        raise Error.new(error['code'], error['message'])
      else
        return result
      end
    rescue => exc
      warn exc
      abort exc
    end
Aborts caller on errors.

 @param [String] method
 @param [Array] params
 @param [Float] timeout seconds
 @raise abort
 @return [Object]