Class: Tarantool::EMDB::OneShardRead

Inherits:
Object
  • Object
show all
Includes:
ParseIProto
Defined in:
lib/tarantool/em_db.rb

Instance Method Summary collapse

Methods included from ParseIProto

#_parse_iproto

Constructor Details

#initialize(replicas, response, feed) ⇒ OneShardRead

Returns a new instance of OneShardRead.



94
95
96
97
98
99
# File 'lib/tarantool/em_db.rb', line 94

def initialize(replicas, response, feed)
  @replicas = replicas
  @i = -1
  @response = response
  @feed = feed
end

Instance Method Details

#call(result = INITIAL) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/tarantool/em_db.rb', line 101

def call(result=INITIAL)
  result = _parse_iproto(result)  unless result == INITIAL
  case result
  when INITIAL, ::IProto::ConnectionError
    begin
      if (@i += 1) >= @replicas.size
        EM.next_tick Curry1.new(@feed, ConnectionError.new("no available connections"))
        return
      end
    end until (repl = @replicas[@i]).could_be_connected?
    repl.send_request(@response.request_type, @response.body, self)
  when Exception
    @feed.call result
  else
    @feed.call @response.parse_response_for_cb(result)
  end
end