Class: Processor::ProcessRunner::Threads
- Inherits:
-
Object
- Object
- Processor::ProcessRunner::Threads
- Defined in:
- lib/processor/process_runner/threads.rb
Direct Known Subclasses
Instance Method Summary collapse
- #call(processor) ⇒ Object
-
#initialize(number_of_threads = 1) ⇒ Threads
constructor
A new instance of Threads.
Constructor Details
#initialize(number_of_threads = 1) ⇒ Threads
Returns a new instance of Threads.
4 5 6 7 |
# File 'lib/processor/process_runner/threads.rb', line 4 def initialize(number_of_threads = 1) @number_of_threads = number_of_threads @threads = [] end |
Instance Method Details
#call(processor) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/processor/process_runner/threads.rb', line 9 def call(processor) join_threads begin processor.records.each do |record| if threads_created >= number_of_threads then join_threads end new_thread(processor, record) do |thread_data_processor, thread_record| begin thread_data_processor.process(thread_record) rescue StandardError => exception thread_data_processor.record_error thread_record, exception end end end ensure # join already created threads join_threads end end |