Class: Async::Process::Child
- Inherits:
-
Object
- Object
- Async::Process::Child
- Defined in:
- lib/async/process/child.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Child
constructor
A new instance of Child.
- #running? ⇒ Boolean
- #wait ⇒ Object
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.close end end |
Instance Method Details
#running? ⇒ Boolean
41 42 43 |
# File 'lib/async/process/child.rb', line 41 def running? @exit_status.nil? end |
#wait ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/async/process/child.rb', line 45 def wait if @exit_status.nil? wait_thread end return @exit_status end |