Class: InThreads::Filler

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

Defined Under Namespace

Classes: Extractor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enum, extractor_count) ⇒ Filler

Returns a new instance of Filler.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/in_threads/filler.rb', line 32

def initialize(enum, extractor_count)
  @extractors = Array.new(extractor_count){ Extractor.new(self) }
  @mutex = Mutex.new
  @filler = Thread.new do
    enum.each do |o|
      synchronize do
        @extractors.each do |extractor|
          extractor.push(o)
        end
      end
    end
  end
end

Instance Attribute Details

#extractorsObject (readonly)

Returns the value of attribute extractors.



31
32
33
# File 'lib/in_threads/filler.rb', line 31

def extractors
  @extractors
end

Instance Method Details

#runObject



46
47
48
# File 'lib/in_threads/filler.rb', line 46

def run
  @filler.run
end

#synchronize(&block) ⇒ Object



50
51
52
# File 'lib/in_threads/filler.rb', line 50

def synchronize(&block)
  @mutex.synchronize(&block)
end