Class: Listen::Adapters::Polling

Inherits:
Listen::Adapter show all
Extended by:
DependencyManager
Defined in:
lib/listen/adapters/polling.rb

Overview

Polling Adapter that works cross-platform and has no dependencies. This is the adapter that uses the most CPU processing power and has higher file IO that the other implementations.

Constant Summary

Constants included from DependencyManager

DependencyManager::BUNDLER_DECLARE_GEM, DependencyManager::GEM_INSTALL_COMMAND, DependencyManager::GEM_LOAD_MESSAGE

Constants inherited from Listen::Adapter

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

Instance Attribute Summary

Attributes inherited from Listen::Adapter

#directories, #latency, #paused

Instance Method Summary collapse

Methods included from DependencyManager

add_loaded, already_loaded?, clear_loaded, dependencies_loaded?, dependency, extended, load_depenencies

Methods inherited from Listen::Adapter

#report_changes, select_and_initialize, #started?, usable?, usable_and_works?, #wait_for_callback, #wait_for_changes, works?

Constructor Details

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

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



17
18
19
20
# File 'lib/listen/adapters/polling.rb', line 17

def initialize(directories, options = {}, &callback)
  @latency ||= DEFAULT_POLLING_LATENCY
  super
end

Instance Method Details

#start(blocking = true) ⇒ Object

Start the adapter.

Parameters:

  • blocking (Boolean) (defaults to: true)

    whether or not to block the current thread after starting



26
27
28
29
30
31
32
33
34
# File 'lib/listen/adapters/polling.rb', line 26

def start(blocking = true)
  @mutex.synchronize do
    return if @stop == false
    super
  end

  @poll_thread = Thread.new { poll }
  @poll_thread.join if blocking
end

#stopObject

Stop the adapter.



38
39
40
41
42
43
44
45
# File 'lib/listen/adapters/polling.rb', line 38

def stop
  @mutex.synchronize do
    return if @stop == true
    super
  end

  @poll_thread.join
end