class Gapic::Rest::ServerStream

def each

Returns:
  • (Enumerator) - if no block is provided

Other tags:
    Yield: - Gives one complete Message object.
def each
  return enum_for :each unless block_given?
  loop do
    while @ready_objs.empty?
      begin
        chunk = @json_enumerator.next
        next unless chunk
        next_json! chunk
      rescue StopIteration
        dangling_content = @obj.strip
        error_expl = "Dangling content left after iterating through the stream. " \
                     "This means that not all content was received or parsed correctly. " \
                     "It is likely a result of server or network error."
        error_text = "#{error_expl}\n Content left unparsed: #{dangling_content}"
        raise Gapic::Common::Error, error_text unless dangling_content.empty?
        return
      end
    end
    yield @message_klass.decode_json @ready_objs.shift, ignore_unknown_fields: true
  end
end