Class: Minibidi::BrowserProcess

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*command) ⇒ BrowserProcess

Returns a new instance of BrowserProcess.



3
4
5
6
7
8
9
# File 'lib/minibidi/browser_process.rb', line 3

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.



22
23
24
# File 'lib/minibidi/browser_process.rb', line 22

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



22
23
24
# File 'lib/minibidi/browser_process.rb', line 22

def stdout
  @stdout
end

Instance Method Details

#disposeObject



17
18
19
20
# File 'lib/minibidi/browser_process.rb', line 17

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

#killObject



11
12
13
14
15
# File 'lib/minibidi/browser_process.rb', line 11

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