lib/knj/event_filemod.rb in knjrbfw-0.0.4 vs lib/knj/event_filemod.rb in knjrbfw-0.0.7

- old
+ new

@@ -2,10 +2,11 @@ attr_reader :args def initialize(args, &block) @args = args @run = true + @mutex = Mutex.new @args[:wait] = 1 if !@args.has_key?(:wait) @mtimes = {} args[:paths].each do |path| @@ -14,11 +15,12 @@ Knj::Thread.new do while @run do break if !@args or !@args[:paths] or @args[:paths].empty? - @args[:paths].clone.each do |path| + @mutex.synchronize do + @args[:paths].each do |path| changed = false if @mtimes and !@mtimes.has_key?(path) and @mtimes.is_a?(Hash) @mtimes[path] = File.mtime(path) end @@ -47,7 +49,11 @@ def destroy @mtimes = {} @run = false @args = nil + end + + def add_path(fpath) + @args[:paths] << fpath end end \ No newline at end of file