class Gapic::Rest::ThreadedEnumerator

@return [Queue] Output queue.
@attribute [r] out_q
@return [Queue] Input queue.
@attribute [r] in_q
chunk = threaded_enumerator.next
@example normal iteration over resources.
ThreadedEnumerator provides the enumerations over the individual chunks of data received from the server.
A class to provide the Enumerable interface to an incoming stream of data.
@private
#

def initialize

Other tags:
    Yieldparam: out_q - output queue
    Yieldparam: in_q - input queue
def initialize
  @in_q = Queue.new
  @out_q = Queue.new
  Thread.new do
    yield @in_q, @out_q
    @out_q.enq nil
  rescue StandardError => e
    @out_q.push e
  end
end

def next

def next
  @in_q.enq :next
  chunk = @out_q.deq
  if chunk.is_a? StandardError
    @out_q.close
    @in_q.close
    raise chunk
  end
  if chunk.nil?
    @out_q.close
    @in_q.close
    raise StopIteration
  end
  chunk
end