Class: PWork::Worker
- Inherits:
-
Object
- Object
- PWork::Worker
- Defined in:
- lib/pwork/worker.rb
Instance Method Summary collapse
-
#add(&block) ⇒ Object
This method is called to add a process to this worker.
-
#execute ⇒ Object
This method is called to execute all processes attached to this worker in parallel on the specified number of threads.
-
#initialize(threads: 5) ⇒ Worker
constructor
A new instance of Worker.
Constructor Details
#initialize(threads: 5) ⇒ Worker
Returns a new instance of Worker.
4 5 6 7 |
# File 'lib/pwork/worker.rb', line 4 def initialize(threads: 5) @processes = [] @thread_count = threads end |
Instance Method Details
#add(&block) ⇒ Object
This method is called to add a process to this worker
10 11 12 |
# File 'lib/pwork/worker.rb', line 10 def add(&block) @processes.push(block) end |
#execute ⇒ Object
This method is called to execute all processes attached to this worker in parallel on the specified number of threads.
15 16 17 18 19 |
# File 'lib/pwork/worker.rb', line 15 def execute @processes.peach(@thread_count) do |item| item.call end end |