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.



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/in_threads.rb', line 111

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

Instance Attribute Details

#enumsObject (readonly)

Enums receiving items



109
110
111
# File 'lib/in_threads.rb', line 109

def enums
  @enums
end