class RethinkDB::Cursor

Public Instance Methods

close() click to toggle source
# File lib/net.rb, line 410
def close
  if @more
    @more = false
    @conn.stop(@token)
    return true
  end
  return false
end
fetch_batch() click to toggle source
# File lib/net.rb, line 429
def fetch_batch
  if @more
    @conn.register_query(@token, @opts)
    @conn.dispatch([Query::QueryType::CONTINUE], @token)
  end
end
next(wait=true) click to toggle source
# File lib/net.rb, line 436
def next(wait=true)
  if @run
    raise ReqlRuntimeError, "Cannot call `next` on a cursor after calling `each`."
  end
  if @more && out_of_date
    raise ReqlRuntimeError, "Connection is closed."
  end
  timeout = wait
  if wait == true
    timeout = nil
  elsif !wait
    timeout = 0
  end

  while @results.length == 0
    raise StopIteration if !@more
    wait_for_batch(timeout)
  end

  @results.shift
end
wait_for_batch(timeout) click to toggle source
# File lib/net.rb, line 419
def wait_for_batch(timeout)
    res = @conn.wait(@token, timeout)
    @results = Shim.response_to_native(res, @msg, @opts)
    if res['t'] == Response::ResponseType::SUCCESS_SEQUENCE
      @more = false
    else
      fetch_batch
    end
end