Class: Spring::Watcher::Polling
Instance Attribute Summary collapse
Attributes inherited from Abstract
#directories, #files, #latency, #root
Instance Method Summary
collapse
Methods inherited from Abstract
#mark_stale, #restart, #stale?, #to_io
Constructor Details
#initialize(root, latency) ⇒ Polling
Returns a new instance of Polling.
6
7
8
9
10
|
# File 'lib/spring/watcher/polling.rb', line 6
def initialize(root, latency)
super
@mtime = 0
@poller = nil
end
|
Instance Attribute Details
#mtime ⇒ Object
Returns the value of attribute mtime.
4
5
6
|
# File 'lib/spring/watcher/polling.rb', line 4
def mtime
@mtime
end
|
Instance Method Details
#add ⇒ Object
16
17
18
19
|
# File 'lib/spring/watcher/polling.rb', line 16
def add(*)
check_stale if @poller
super
end
|
#check_stale ⇒ Object
12
13
14
|
# File 'lib/spring/watcher/polling.rb', line 12
def check_stale
synchronize { mark_stale if mtime < compute_mtime }
end
|
#start ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/spring/watcher/polling.rb', line 21
def start
unless @poller
@poller = Thread.new {
Thread.current.abort_on_exception = true
loop do
Kernel.sleep latency
check_stale
end
}
end
end
|
#stop ⇒ Object
34
35
36
37
38
39
|
# File 'lib/spring/watcher/polling.rb', line 34
def stop
if @poller
@poller.kill
@poller = nil
end
end
|
#subjects_changed ⇒ Object
41
42
43
|
# File 'lib/spring/watcher/polling.rb', line 41
def subjects_changed
@mtime = compute_mtime
end
|