Class: Async::Process::Child

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, **options) ⇒ Child

Returns a new instance of Child.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/async/process/child.rb', line 9

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

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



25
26
27
# File 'lib/async/process/child.rb', line 25

def pid
  @pid
end

Instance Method Details

#kill(signal = :TERM) ⇒ Object



31
32
33
# File 'lib/async/process/child.rb', line 31

def kill(signal = :TERM)
	::Process.kill(signal, -@pid)
end

#running?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/async/process/child.rb', line 27

def running?
	@exit_status.nil?
end

#waitObject



35
36
37
38
39
40
41
# File 'lib/async/process/child.rb', line 35

def wait
	if @exit_status.nil?
		wait_thread
	end
	
	return @exit_status
end