Class: InThreads::Filler::Extractor

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/in_threads/filler.rb

Instance Method Summary collapse

Methods included from Enumerable

#in_threads

Constructor Details

#initialize(filler) ⇒ Extractor

Returns a new instance of Extractor.



8
9
10
11
# File 'lib/in_threads/filler.rb', line 8

def initialize(filler)
  @filler = filler
  @queue = []
end

Instance Method Details

#eachObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/in_threads/filler.rb', line 17

def each
  begin
    loop do
      while @filler.synchronize{ @queue.empty? }
        @filler.run
      end
      yield @filler.synchronize{ @queue.shift }
    end
  rescue ThreadError => e
  end
  nil # non reusable
end

#push(o) ⇒ Object



13
14
15
# File 'lib/in_threads/filler.rb', line 13

def push(o)
  @queue.push(o)
end