Class: Async::Process::Child

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Child.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sc2ai/overrides/async/process/child.rb', line 8

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

  if Gem.win_platform?
    options[:new_pgroup] = true
  else
    options[:pgroup] = true
  end

  @pid = ::Process.spawn(*args, **options)

  @thread = Thread.new do
    _, @exit_status = ::Process.wait2(@pid)
    @output.close
  end
end