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, #on_stale, #restart, #stale?
Constructor Details
#initialize(root, latency) ⇒ Polling
Returns a new instance of Polling.
8
9
10
11
12
|
# File 'lib/spring/watcher/polling.rb', line 8
def initialize(root, latency)
super
@mtime = 0
@poller = nil
end
|
Instance Attribute Details
#mtime ⇒ Object
Returns the value of attribute mtime.
6
7
8
|
# File 'lib/spring/watcher/polling.rb', line 6
def mtime
@mtime
end
|
Instance Method Details
#add ⇒ Object
18
19
20
21
|
# File 'lib/spring/watcher/polling.rb', line 18
def add(*)
check_stale if @poller
super
end
|
#check_stale ⇒ Object
14
15
16
|
# File 'lib/spring/watcher/polling.rb', line 14
def check_stale
synchronize { mark_stale if mtime < compute_mtime }
end
|
#start ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/spring/watcher/polling.rb', line 23
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
36
37
38
39
40
41
|
# File 'lib/spring/watcher/polling.rb', line 36
def stop
if @poller
@poller.kill
@poller = nil
end
end
|
#subjects_changed ⇒ Object
43
44
45
|
# File 'lib/spring/watcher/polling.rb', line 43
def subjects_changed
@mtime = compute_mtime
end
|