Class: Forkit::Enumerable

Inherits:
Object
  • Object
show all
Defined in:
lib/forkit/enumerable.rb

Overview

The enumerable allows for concurrent processing via JDK7’s ForkJoinPool.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(objects, threshold) ⇒ Forkit::Enumerable

Instantiate the new concurrent enumerable.

Examples:

Create the enumerable.

Enumerable.new([ 1, 2, 3 ], 100000)

Parameters:

  • objects (Array<Object>)

    The object array.

  • threshold (Integer)

    The single process threshold count.

Since:

  • 0.1.0



24
25
26
# File 'lib/forkit/enumerable.rb', line 24

def initialize(objects, threshold)
  @objects, @threshold = objects, threshold
end

Instance Attribute Details

#objectsObject (readonly)

Returns the value of attribute objects.



11
12
13
# File 'lib/forkit/enumerable.rb', line 11

def objects
  @objects
end

#objects The array to process.(Thearraytoprocess.) ⇒ Object (readonly)



11
# File 'lib/forkit/enumerable.rb', line 11

attr_reader :objects, :threshold

#thresholdObject (readonly)

Returns the value of attribute threshold.



11
12
13
# File 'lib/forkit/enumerable.rb', line 11

def threshold
  @threshold
end

#threshold The single process threshold count.(Thesingleprocessthresholdcount.) ⇒ Object (readonly)



11
# File 'lib/forkit/enumerable.rb', line 11

attr_reader :objects, :threshold

Instance Method Details

#each(&block) ⇒ nil

Execute the provided block for each element in the array.

Examples:

Execute in parallel.

enum.each do |object|
  p object
end

Returns:

  • (nil)

    nil.

Since:

  • 0.1.0



38
39
40
41
42
43
44
# File 'lib/forkit/enumerable.rb', line 38

def each(&block)
  if block_given?
    ForkJoinPool.new.invoke(Iterator.new(objects, threshold, block))
  else
    objects.each
  end
end