Class: Charai::BrowserProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/charai/browser_process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*command) ⇒ BrowserProcess

Returns a new instance of BrowserProcess.



5
6
7
8
9
10
11
# File 'lib/charai/browser_process.rb', line 5

def initialize(*command)
  stdin, @stdout, @stderr, @thread = Open3.popen3(*command, { pgroup: true })
  stdin.close
  @pid = @thread.pid
rescue Errno::ENOENT => err
  raise LaunchError.new("Failed to launch browser process: #{err}")
end

Instance Attribute Details

#stderrObject (readonly)

Returns the value of attribute stderr.



24
25
26
# File 'lib/charai/browser_process.rb', line 24

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



24
25
26
# File 'lib/charai/browser_process.rb', line 24

def stdout
  @stdout
end

Instance Method Details

#disposeObject



19
20
21
22
# File 'lib/charai/browser_process.rb', line 19

def dispose
  [@stdout, @stderr].each { |io| io.close unless io.closed? }
  @thread.terminate
end

#killObject



13
14
15
16
17
# File 'lib/charai/browser_process.rb', line 13

def kill
  Process.kill(:KILL, @pid)
rescue Errno::ESRCH
  # already killed
end