class Rcom::Request

Attributes

channel[R]
node[R]

Public Class Methods

new(params) click to toggle source
# File lib/rcom/rpc.rb, line 5
def initialize(params)
  @node = params[:node]
  @channel = params[:channel]
end

Public Instance Methods

method_missing(name, args) click to toggle source
# File lib/rcom/rpc.rb, line 10
def method_missing(name, args)
  begin
    request = {
      id: SecureRandom.hex,
      method: name,
      args: args || ''
    }

    node.rpush(channel, request.to_msgpack)
    ch, response = node.brpop(request[:id], timeout=10)

    MessagePack.unpack(response, symbolize_keys: true)
  rescue
    return nil
  end
end