BigW Consortium Gitlab

queue_enumerator.rb 431 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
module Gitlab
  module GitalyClient
    class QueueEnumerator
      def initialize
        @queue = Queue.new
      end

      def push(elem)
        @queue << elem
      end

      def close
        push(:close)
      end

      def each
        return enum_for(:each) unless block_given?

        loop do
          elem = @queue.pop
          break if elem == :close

          yield elem
        end
      end
    end
  end
end