Class: Listen::Adapter::Polling
- Inherits:
-
Base
- Object
- Base
- Listen::Adapter::Polling
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
- DEFAULT_POLLING_LATENCY =
1.0
Constants inherited
from Base
Base::DEFAULT_LATENCY
Instance Attribute Summary
Attributes inherited from Base
#listener
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#_directories_path, #_notify_change, #initialize
Class Method Details
.usable? ⇒ Boolean
12
13
14
|
# File 'lib/listen/adapter/polling.rb', line 12
def self.usable?
true
end
|
Instance Method Details
#_latency ⇒ Object
22
23
24
|
# File 'lib/listen/adapter/polling.rb', line 22
def _latency
listener.options[:latency] || DEFAULT_POLLING_LATENCY
end
|
#_nap_time ⇒ Object
40
41
42
43
44
45
|
# File 'lib/listen/adapter/polling.rb', line 40
def _nap_time
start = Time.now.to_f
yield
nap_time = _latency - (Time.now.to_f - start)
sleep(nap_time) if nap_time > 0
end
|
#_napped_loop ⇒ Object
34
35
36
37
38
|
# File 'lib/listen/adapter/polling.rb', line 34
def _napped_loop
loop do
_nap_time { yield }
end
end
|
#_poll_directories ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/listen/adapter/polling.rb', line 26
def _poll_directories
_napped_loop do
listener.directories.each do |path|
_notify_change(path, type: 'Dir', recursive: true)
end
end
end
|
#start ⇒ Object
16
17
18
|
# File 'lib/listen/adapter/polling.rb', line 16
def start
Thread.new { _poll_directories }
end
|