class Phrender::PhantomJSSession

Attributes

page[RW]
rendered[RW]
stderr[RW]
stdin[RW]
stdout[RW]
wait_thr[RW]

Public Class Methods

new(cmd, timeout) click to toggle source
# File lib/phrender/phantom_js_session.rb, line 9
def initialize(cmd, timeout)
  @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(cmd)
  @start_time = Time.now
  @rendered = false
  @timeout = timeout
end

Public Instance Methods

expired?() click to toggle source
# File lib/phrender/phantom_js_session.rb, line 16
def expired?
  (Time.now - @start_time) >= @timeout
end
shutdown() click to toggle source
# File lib/phrender/phantom_js_session.rb, line 20
def shutdown
  [ @stdin, @stdout, @stderr ].each do |pipe|
    begin
      pipe.close
    rescue IOError
    end
  end
  begin
    Process.kill("TERM", @wait_thr.pid)
  rescue Errno::ESRCH
  end
end