def monitor(termination_pipe)
raise "You must call #scan first" if !@apps
watcher = PhusionPassenger::Utils::FileSystemWatcher.new(@watchlist, termination_pipe)
if wait_on_io(termination_pipe, 3)
return
end
while true
changed = watcher.wait_for_change
watcher.close
if changed
old_apps = @apps
if wait_on_io(termination_pipe, 0.25)
return
end
new_apps = scan
watcher = PhusionPassenger::Utils::FileSystemWatcher.new(@watchlist, termination_pipe)
if old_apps != new_apps
yield(new_apps)
end
if wait_on_io(termination_pipe, 3)
return
end
else
return
end
end
ensure
watcher.close if watcher
end