Skip to content

Infinite series expansion #211

@cyclotron3k

Description

@cyclotron3k

@source = source.to_a unless @lambda # turn Range and other Enumerable-s into an Array

Parallel provides each and map methods, implying it works well with Enumerables, but it fails with the following [contrived] use case:

require 'parallel'
require 'prime'

primes = Prime.to_enum
private_key = 12344567899

Parallel.each(primes, in_threads: 16) do |prime|
  if private_key % prime == 0
    puts "Found factor: #{prime}"
    raise Parallel::Break
  end
end

...because if the first argument to Parallel.each is not a lambda, .to_a is called and it tries to expand the infinite series.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions