Class: VagrantPlugins::GatlingRsync::ListenWindows

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-gatling-rsync/listen/listenwindows.rb

Instance Method Summary collapse

Constructor Details

#initialize(paths, ignores, latency, logger, callback) ⇒ ListenWindows

Returns a new instance of ListenWindows.



8
9
10
11
12
13
14
# File 'lib/vagrant-gatling-rsync/listen/listenwindows.rb', line 8

def initialize(paths, ignores, latency, logger, callback)
  @paths = paths
  @ignores = ignores
  @latency = latency
  @logger = logger
  @callback = callback
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vagrant-gatling-rsync/listen/listenwindows.rb', line 16

def run
  @logger.info("Listening via: WDM on Windows.")
  monitor = WDM::Monitor.new
  changes = Queue.new
  @paths.keys.each do |path|
    monitor.watch_recursively(path.dup) { |change| changes << change }
  end
  Thread.new { monitor.run! }

  loop do
    directories = Set.new
    begin
      loop do
        change = Timeout::timeout(@latency) {
          changes.pop
        }
        directories << change.path
      end
    rescue Timeout::Error
      @logger.info("Breaking out of the loop at #{Time.now.to_s}.")
    end

    @logger.info(directories.inspect) unless directories.empty?

    @callback.call(@paths, @ignores, directories) unless directories.empty?
  end
end