Class: EnumeratorQueue

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
src/ruby/pb/test/server.rb,
src/ruby/bin/math_server.rb

Overview

A EnumeratorQueue wraps a Queue to yield the items added to it.

Instance Method Summary collapse

Constructor Details

#initialize(sentinel) ⇒ EnumeratorQueue


137
138
139
140
# File 'src/ruby/pb/test/server.rb', line 137

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

Instance Method Details

#each_itemObject


142
143
144
145
146
147
148
149
150
# File 'src/ruby/pb/test/server.rb', line 142

def each_item
  return enum_for(:each_item) unless block_given?
  loop do
    r = @q.pop
    break if r.equal?(@sentinel)
    fail r if r.is_a? Exception
    yield r
  end
end