Class: RelatonBib::WorkersPool
- Defined in:
- lib/relaton_bib/workers_pool.rb
Overview
Workers poll.
Instance Attribute Summary collapse
-
#nb_hits ⇒ Object
Returns the value of attribute nb_hits.
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #end ⇒ Object
-
#initialize(num_workers = 2) ⇒ WorkersPool
constructor
A new instance of WorkersPool.
- #result ⇒ Object
- #size ⇒ Object
- #worker(&block) ⇒ Object
Constructor Details
#initialize(num_workers = 2) ⇒ WorkersPool
Returns a new instance of WorkersPool.
8 9 10 11 12 13 |
# File 'lib/relaton_bib/workers_pool.rb', line 8 def initialize(num_workers = 2) @num_workers = num_workers < 2 ? 2 : num_workers @queue = SizedQueue.new(num_workers * 2) @result = [] @nb_hits = 0 end |
Instance Attribute Details
#nb_hits ⇒ Object
Returns the value of attribute nb_hits.
6 7 8 |
# File 'lib/relaton_bib/workers_pool.rb', line 6 def nb_hits @nb_hits end |
Instance Method Details
#<<(item) ⇒ Object
30 31 32 33 |
# File 'lib/relaton_bib/workers_pool.rb', line 30 def <<(item) @queue << item self end |
#end ⇒ Object
35 36 37 |
# File 'lib/relaton_bib/workers_pool.rb', line 35 def end @num_workers.times { @queue << :END } end |
#result ⇒ Object
25 26 27 28 |
# File 'lib/relaton_bib/workers_pool.rb', line 25 def result @threads.each(&:join) @result end |
#size ⇒ Object
39 40 41 |
# File 'lib/relaton_bib/workers_pool.rb', line 39 def size @result.size end |