Class: ThreadedPipe

Inherits:
Object
  • Object
show all
Defined in:
lib/threaded_pipe.rb,
lib/threaded_pipe/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Constructor Details

#initialize(*procs) ⇒ ThreadedPipe

Returns a new instance of ThreadedPipe.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/threaded_pipe.rb', line 4

def initialize(*procs)
  pipes = build_pipes(procs.size - 1)

  @threads = procs.map.with_index do |procedure, index|
    Thread.new(*pipes[index]) do |*pipes|
      procedure.call(*pipes)
    ensure
      pipes.each(&:close)
    end
  end
end

Instance Method Details

#joinObject



16
17
18
# File 'lib/threaded_pipe.rb', line 16

def join
  @threads.each(&:join)
end

#valuesObject



20
21
22
# File 'lib/threaded_pipe.rb', line 20

def values
  @threads.map(&:value)
end