Sha256: 29887619dec0f721b558c1e50421294c59c1b787cf46c7006424e1428b26df3b

Contents?: true

Size: 754 Bytes

Versions: 16

Compression:

Stored size: 754 Bytes

Contents

module Enumerable

  def parallel
    ParallelEnumerable.new(self)
  end

end

class ParallelEnumerable

  def initialize(enumerable)
    @enumerable = enumerable
  end



  def each
    enumerable.map do |item|
      Houston.async! do
        yield item
      end
    end.each(&:join)
  end

  def map
    queue = Queue.new

    each do |item|
      queue << yield(item)
    end

    [].tap do |results|
      results.push queue.pop until queue.empty?
    end
  end



  def method_missing(method_name, *args, &block)
    return super unless enumerable.respond_to?(method_name)

    $stderr.puts "[parallel-enumerable] ##{method_name} is not defined"
    enumerable.public_send(method_name, *args, &block)
  end

private

  attr_reader :enumerable

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
houston-core-0.9.2 lib/parallel_enumerable.rb
houston-core-0.9.1 lib/parallel_enumerable.rb
houston-core-0.9.0 lib/parallel_enumerable.rb
houston-core-0.9.0.rc1 lib/parallel_enumerable.rb
houston-core-0.8.4 lib/parallel_enumerable.rb
houston-core-0.8.3 lib/parallel_enumerable.rb
houston-core-0.8.2 lib/parallel_enumerable.rb
houston-core-0.8.1 lib/parallel_enumerable.rb
houston-core-0.8.0 lib/parallel_enumerable.rb
houston-core-0.8.0.pre2 lib/parallel_enumerable.rb
houston-core-0.8.0.pre lib/parallel_enumerable.rb
houston-core-0.7.0 lib/parallel_enumerable.rb
houston-core-0.7.0.beta4 lib/parallel_enumerable.rb
houston-core-0.7.0.beta3 lib/parallel_enumerable.rb
houston-core-0.7.0.beta2 lib/parallel_enumerable.rb
houston-core-0.7.0.beta lib/parallel_enumerable.rb