Class: PVC::BlockPiece::Runner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Runner

Returns a new instance of Runner.



6
7
8
9
10
11
# File 'lib/pvc/block_piece.rb', line 6

def initialize(&block)
  @block = block
  @read, @write = IO.pipe
  @read.close_on_exec = true
  @write.close_on_exec = true
end

Instance Attribute Details

#returnObject (readonly)

Returns the value of attribute return.



30
31
32
# File 'lib/pvc/block_piece.rb', line 30

def return
  @return
end

Instance Method Details

#finishObject



24
25
26
27
28
# File 'lib/pvc/block_piece.rb', line 24

def finish
  @write.close
  @thread.join
  @read.close
end

#start(following_piece) ⇒ Object



17
18
19
20
21
22
# File 'lib/pvc/block_piece.rb', line 17

def start(following_piece)
  @return = nil
  @thread = Thread.new do
    @return = @block.call(@read, following_piece.stdin)
  end
end

#stdinObject



13
14
15
# File 'lib/pvc/block_piece.rb', line 13

def stdin
  @write
end