Class: Fabric::EnumeratorQueue

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/fabric/queue.rb,
lib/fabric/enumerator_queue.rb

Instance Method Summary collapse

Constructor Details

#initialize(sentinel) ⇒ EnumeratorQueue

Returns a new instance of EnumeratorQueue.



7
8
9
10
# File 'lib/fabric/queue.rb', line 7

def initialize(sentinel)
  @q = Queue.new
  @sentinel = sentinel
end

Instance Method Details

#eachObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fabric/queue.rb', line 12

def each
  return enum_for(:each) unless block_given?

  loop do
    r = @q.pop

    break if r.equal?(@sentinel)

    raise r if r.is_a? Exception

    yield r
  end
end