Sha256: bbdcfb45d0b0bd742a2de81833e4a366b0dfd456d3aad5fd201016940eeaeb98

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

# @TODO: Note that this is entirely untested and not yet implemented.

require "wdm"

module VagrantPlugins
  module RsyncBlitz
    class ListenWindows
      def initialize(paths, ignores, latency, logger, callback)
        @paths = paths
        @ignores = ignores
        @latency = latency
        @logger = logger
        @callback = callback
      end

      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-rsync-blitz-2.0.0 lib/vagrant-rsync-blitz/listen/listenwindows.rb