module Enumerable
Public Instance Methods
ordered_parallel_map() { |item| ... }
click to toggle source
# File lib/slugforge/helper/enumerable.rb, line 32 def ordered_parallel_map queue = Queue.new self.map.with_index do |item, index| Thread.new do # NOTE: You can not do anything that is not thread safe in this block... queue << [index, yield(item)] end end.each(&:join) [].tap do |results| results << queue.pop until queue.empty? end.sort.map {|index, item| item } end
parallel_map() { |item| ... }
click to toggle source
# File lib/slugforge/helper/enumerable.rb, line 2 def parallel_map queue = Queue.new self.map do |item| Thread.new do # NOTE: You can not do anything that is not thread safe in this block... queue << yield(item) end end.each(&:join) [].tap do |results| results << queue.pop until queue.empty? end end
parallel_map_with_index() { |item, index| ... }
click to toggle source
# File lib/slugforge/helper/enumerable.rb, line 17 def parallel_map_with_index queue = Queue.new self.map.with_index do |item, index| Thread.new do # NOTE: You can not do anything that is not thread safe in this block... queue << yield(item, index) end end.each(&:join) [].tap do |results| results << queue.pop until queue.empty? end end