Class: WaitPidTimeout

Inherits:
Object
  • Object
show all
Defined in:
lib/rnote/edit.rb

Instance Method Summary collapse

Constructor Details

#initialize(pid, timeout) ⇒ WaitPidTimeout

wait in ruby doesn’t take a timeout parameter so, join with timeout => wait with timeout launch a thread that does a wait on the pid. then its just a matter of joining that thread, with a timeout.



13
14
15
16
# File 'lib/rnote/edit.rb', line 13

def initialize(pid,timeout)
  @pid = pid
  @timeout = timeout
end

Instance Method Details

#waitObject



18
19
20
21
22
23
24
25
26
# File 'lib/rnote/edit.rb', line 18

def wait

  @thread ||= Thread.new(@pid) do |pid|
    Process.waitpid(pid)
  end

  !!@thread.join(@timeout)

end