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

- (Forkit::Enumerable) initialize(objects, threshold)

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

- (Object) objects (readonly)



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

def objects
  @objects
end

- (Object) threshold (readonly)



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

def threshold
  @threshold
end

Instance Method Details

- (nil) each(&block)

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