Rewrite to use the new rb-inotify API

This commit is contained in:
Paul van Tilburg 2018-06-22 20:07:26 +02:00
parent 96a6d3533c
commit 712b17c308
1 changed files with 5 additions and 10 deletions

View File

@ -186,20 +186,15 @@ end
## Main event loop
# Add input file with dependancies to the watch list and start event loop.
i = INotify::Notifier.new
notifier = INotify::Notifier.new
dirs = files.map { |file| File.dirname(file) }
dirmap = {}
dirs.each do |dir|
# Use a watch descriptor per directory and save it for later.
wd = i.add_watch(dir, Inotify::CLOSE_WRITE)
dirmap[wd] = dir
end
# Process the events, recompile and reload when necessary.
i.each_event do |ev|
# Only recompile if files are modified that we are interested in.
if files.include?(dirmap[ev.wd] + "/" + ev.name)
# Set up a watch per directory
notifier.watch(dir, :close_write) do
puts "I: file #{ev.name} modified, compiling #{infile}..."
compile(infile, mode)
reload(infile, mode)
end
end
notifier.run