class Listen::Adapters::Windows

Adapter implementation for Windows `fchange`.

Public Class Methods

new(directories, options = {}, &callback) click to toggle source

Initializes the Adapter. See {Listen::Adapter#initialize} for more info.

Calls superclass method Listen::Adapter.new
# File lib/listen/adapters/windows.rb, line 12
def initialize(directories, options = {}, &callback)
  super
  @worker = init_worker
end
usable?() click to toggle source

Checks if the adapter is usable on the current OS.

@return [Boolean] whether usable or not

# File lib/listen/adapters/windows.rb, line 49
def self.usable?
  return false unless RbConfig::CONFIG['target_os'] =~ /mswin|mingw/

  require 'rb-fchange'
  true
rescue LoadError
  false
end

Public Instance Methods

start(blocking = true) click to toggle source

Starts the adapter.

@param [Boolean] blocking whether or not to block the current thread after starting

Calls superclass method Listen::Adapter#start
# File lib/listen/adapters/windows.rb, line 21
def start(blocking = true)
  @mutex.synchronize do
    return if @stop == false
    super
  end

  @worker_thread = Thread.new { @worker.run }
  @poll_thread   = Thread.new { poll_changed_dirs(true) }
  @poll_thread.join if blocking
end
stop() click to toggle source

Stops the adapter.

Calls superclass method Listen::Adapter#stop
# File lib/listen/adapters/windows.rb, line 34
def stop
  @mutex.synchronize do
    return if @stop == true
    super
  end

  @worker.stop
  Thread.kill(@worker_thread) if @worker_thread
  @poll_thread.join
end

Private Instance Methods

init_worker() click to toggle source

Initializes a FChange worker and adds a watcher for each directory passed to the adapter.

@return [FChange::Notifier] initialized worker

# File lib/listen/adapters/windows.rb, line 65
def init_worker
  FChange::Notifier.new.tap do |worker|
    @directories.each do |directory|
      worker.watch(directory, :all_events, :recursive) do |event|
        next if @paused
        @mutex.synchronize do
          @changed_dirs << File.expand_path(event.watcher.path)
        end
      end
    end
  end
end