class PWork::Worker
Public Class Methods
new(threads: 5)
click to toggle source
# File lib/pwork/worker.rb, line 4 def initialize(threads: 5) @processes = [] @thread_count = threads end
Public Instance Methods
add(&block)
click to toggle source
This method is called to add a process to this worker
# File lib/pwork/worker.rb, line 10 def add(&block) @processes.push(block) end
execute()
click to toggle source
This method is called to execute all processes attached to this worker in parallel on the specified number of threads.
# File lib/pwork/worker.rb, line 15 def execute @processes.peach(@thread_count) do |item| item.call end end