Class: Listen::Adapters::Windows

Inherits:
Listen::Adapter show all
Defined in:
lib/listen/adapters/windows.rb

Overview

Adapter implementation for Windows ‘fchange`.

Constant Summary

Constants inherited from Listen::Adapter

Listen::Adapter::DEFAULT_LATENCY, Listen::Adapter::POLLING_FALLBACK_MESSAGE

Instance Attribute Summary

Attributes inherited from Listen::Adapter

#directories, #latency, #paused

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Listen::Adapter

select_and_initialize, #started?, usable_and_works?, #wait_for_callback, works?

Constructor Details

#initialize(directories, options = {}, &callback) ⇒ Windows

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



12
13
14
15
# File 'lib/listen/adapters/windows.rb', line 12

def initialize(directories, options = {}, &callback)
  super
  @worker = init_worker
end

Class Method Details

.usable?Boolean

Checks if the adapter is usable on the current OS.

Returns:

  • (Boolean)

    whether usable or not



49
50
51
52
53
54
55
56
# File 'lib/listen/adapters/windows.rb', line 49

def self.usable?
  return false unless RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i

  require 'rb-fchange'
  true
rescue LoadError
  false
end

Instance Method Details

#start(blocking = true) ⇒ Object

Starts the adapter.

Parameters:

  • blocking (Boolean) (defaults to: true)

    whether or not to block the current thread after starting



21
22
23
24
25
26
27
28
29
30
# 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

#stopObject

Stops the adapter.



34
35
36
37
38
39
40
41
42
43
# 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