Class: InThreads::Splitter

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

Overview

Yield objects of one enum in multiple places

Defined Under Namespace

Classes: Transfer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enumerable, enum_count) ⇒ Splitter

Returns a new instance of Splitter.



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/in_threads.rb', line 99

def initialize(enumerable, enum_count)
  @enums = Array.new(enum_count){ Transfer.new }
  @filler = Thread.new do
    enumerable.each do |*args|
      @enums.each do |enum|
        enum << args
      end
    end
    @enums.each(&:finish)
  end
end

Instance Attribute Details

#enumsObject (readonly)

Enums receiving items



97
98
99
# File 'lib/in_threads.rb', line 97

def enums
  @enums
end