Class: Spring::Watcher::Polling

Inherits:
Abstract
  • Object
show all
Defined in:
lib/spring/watcher/polling.rb

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

#mtimeObject (readonly)

Returns the value of attribute mtime.



6
7
8
# File 'lib/spring/watcher/polling.rb', line 6

def mtime
  @mtime
end

Instance Method Details

#addObject



18
19
20
21
# File 'lib/spring/watcher/polling.rb', line 18

def add(*)
  check_stale if @poller
  super
end

#check_staleObject



14
15
16
# File 'lib/spring/watcher/polling.rb', line 14

def check_stale
  synchronize { mark_stale if mtime < compute_mtime }
end

#startObject



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

#stopObject



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_changedObject



43
44
45
# File 'lib/spring/watcher/polling.rb', line 43

def subjects_changed
  @mtime = compute_mtime
end