Class: Listen::Adapter::Polling

Inherits:
Base
  • Object
show all
Defined in:
lib/listen/adapter/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 than the other implementations.

Constant Summary collapse

OS_REGEXP =

match every OS

//
DEFAULTS =
{ latency: 1.0, wait_for_delay: 0.05 }.freeze

Instance Attribute Summary

Attributes inherited from Base

#config, #options

Instance Method Summary collapse

Methods inherited from Base

#_log_exception, #_queue_change, #_stop, #_timed, #configure, #initialize, #start, #started?, #stop, usable?

Constructor Details

This class inherits a constructor from Listen::Adapter::Base

Instance Method Details

#_configure(_, &callback) ⇒ Object (private)



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

def _configure(_, &callback)
  @polling_callbacks ||= []
  @polling_callbacks << callback
end

#_process_event(dir, _) ⇒ Object (private)



35
36
37
# File 'lib/listen/adapter/polling.rb', line 35

def _process_event(dir, _)
  _queue_change(:dir, dir, '.', recursive: true)
end

#_runObject (private)



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/listen/adapter/polling.rb', line 22

def _run
  loop do
    start = MonotonicTime.now
    @polling_callbacks.each do |callback|
      callback.call(nil)
      if (nap_time = options.latency - (MonotonicTime.now - start)) > 0
        # TODO: warn if nap_time is negative (polling too slow)
        sleep(nap_time)
      end
    end
  end
end