# File lib/parallel.rb, line 150 def each(array, options={}, &block) map(array, options.merge(:preserve_results => false), &block) array end
# File lib/parallel.rb, line 155 def each_with_index(array, options={}, &block) each(array, options.merge(:with_index => true), &block) end
# File lib/parallel.rb, line 144 def in_processes(options = {}, &block) count, options = extract_count_from_options(options) count ||= processor_count map(0...count, options.merge(:in_processes => count), &block) end
# File lib/parallel.rb, line 127 def in_threads(options={:count => 2}) count, options = extract_count_from_options(options) out = [] threads = [] count.times do |i| threads[i] = Thread.new do out[i] = yield(i) end end kill_on_ctrl_c(threads) { wait_for_threads(threads) } out end
# File lib/parallel.rb, line 159 def map(array, options = {}, &block) options[:mutex] = Mutex.new if RUBY_PLATFORM =~ /java/ and not options[:in_processes] method = :in_threads size = options[method] || processor_count elsif options[:in_threads] method = :in_threads size = options[method] else method = :in_processes if Process.respond_to?(:fork) size = options[method] || processor_count else $stderr.puts "Warning: Process.fork is not supported by this Ruby" size = 0 end end items = ItemWrapper.new(array, options[:mutex]) size = [items.producer? ? size : items.size, size].min options[:return_results] = (options[:preserve_results] != false || !!options[:finish]) add_progress_bar!(items, options) if size == 0 work_direct(items, options, &block) elsif method == :in_threads work_in_threads(items, options.merge(:count => size), &block) else work_in_processes(items, options.merge(:count => size), &block) end end
Generated with the Darkfish Rdoc Generator 2.