Class: WaitPidTimeout

Inherits:
Object
  • Object
show all
Defined in:
lib/rnote/noun/note/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.



14
15
16
17
# File 'lib/rnote/noun/note/edit.rb', line 14

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

Instance Method Details

#waitObject



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

def wait

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

  !!@thread.join(@timeout)

end