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 }

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

_log, #_log, #_queue_change, #configure, #initialize, local_fs?, #start, usable?

Constructor Details

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

Instance Method Details

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



15
16
17
18
# File 'lib/listen/adapter/polling.rb', line 15

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

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



31
32
33
# File 'lib/listen/adapter/polling.rb', line 31

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

#_runObject (private)



20
21
22
23
24
25
26
27
28
29
# File 'lib/listen/adapter/polling.rb', line 20

def _run
  loop do
    start = Time.now.to_f
    @polling_callbacks.each do |callback|
      callback.call(nil)
      nap_time = options.latency - (Time.now.to_f - start)
      sleep(nap_time) if nap_time > 0
    end
  end
end