Class: Redom::ThreadPool
- Inherits:
-
Object
- Object
- Redom::ThreadPool
- Defined in:
- lib/redom/thread_pool.rb
Instance Method Summary collapse
-
#initialize(opts) ⇒ ThreadPool
constructor
A new instance of ThreadPool.
- #start ⇒ Object
- #stop ⇒ Object
- #worker ⇒ Object
Constructor Details
#initialize(opts) ⇒ ThreadPool
Returns a new instance of ThreadPool.
3 4 5 6 7 8 9 |
# File 'lib/redom/thread_pool.rb', line 3 def initialize(opts) @workers = Array.new @idx = 0 opts[:worker].times { @workers << Worker.new } end |
Instance Method Details
#start ⇒ Object
11 12 13 14 15 |
# File 'lib/redom/thread_pool.rb', line 11 def start @workers.each { |worker| worker.start } end |
#stop ⇒ Object
17 18 19 20 21 |
# File 'lib/redom/thread_pool.rb', line 17 def stop @workers.each { |worker| worker.stop } end |
#worker ⇒ Object
23 24 25 |
# File 'lib/redom/thread_pool.rb', line 23 def worker @workers[(@idx += 1) == @workers.size ? @idx = 0 : @idx] end |