module Build::Files

def self.run_with_fsevent(monitor, options = {}, &block)

def self.run_with_fsevent(monitor, options = {}, &block)
	require 'rb-fsevent'
	
	fsevent ||= FSEvent.new
	
	catch(:interrupt) do
		while true
			fsevent.watch monitor.roots do |directories|
				monitor.update(directories)
		
				yield
		
				if monitor.updated
					fsevent.stop
				end
			end
	
			fsevent.run
		end
	end
end

def self.run_with_polling(monitor, options = {}, &block)

def self.run_with_polling(monitor, options = {}, &block)
	catch(:interrupt) do
		while true
			monitor.update(monitor.roots)
	
			yield
	
			sleep(options[:latency] || 5.0)
		end
	end
end