Class: Async::Process::Child

Inherits:
Object
  • Object
show all
Defined in:
lib/async/process/child.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Child

Returns a new instance of Child.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/async/process/child.rb', line 26

def initialize(*args)
  # Setup a cross-thread notification pipe - nio4r can't monitor pids unfortunately.
  pipe = ::IO.pipe
  @input = Async::IO::Generic.new(pipe.first)
  @output = pipe.last
  
  @exit_status = nil
  @pid = ::Process.spawn(*args)
  
  @thread = Thread.new do
    _, @exit_status = ::Process.wait2(@pid)
    @output.write(".")
  end
end

Instance Method Details

#waitObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/async/process/child.rb', line 41

def wait
  unless @exit_status
    @input.read(1)
    @thread.join
    
    # We are done with the nofication pipe:
    @input.close
    @output.close
  end
  
  return @exit_status
end