Class: RuVim::FileWatcher::PollingWatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ruvim/file_watcher.rb

Constant Summary collapse

MIN_INTERVAL =
0.1
MAX_INTERVAL =
3.0
BACKOFF_FACTOR =
1.5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, &on_event) ⇒ PollingWatcher

Returns a new instance of PollingWatcher.



22
23
24
25
26
27
28
29
30
# File 'lib/ruvim/file_watcher.rb', line 22

def initialize(path, &on_event)
  @path = path
  @on_event = on_event
  @offset = File.exist?(path) ? File.size(path) : 0
  @file_existed = File.exist?(path)
  @current_interval = MIN_INTERVAL
  @thread = nil
  @stop = false
end

Instance Attribute Details

#current_intervalObject (readonly)

Returns the value of attribute current_interval.



18
19
20
# File 'lib/ruvim/file_watcher.rb', line 18

def current_interval
  @current_interval
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/ruvim/file_watcher.rb', line 44

def alive?
  @thread&.alive? || false
end

#backendObject



20
# File 'lib/ruvim/file_watcher.rb', line 20

def backend = :polling

#startObject



32
33
34
35
# File 'lib/ruvim/file_watcher.rb', line 32

def start
  @stop = false
  @thread = Thread.new { poll_loop }
end

#stopObject



37
38
39
40
41
42
# File 'lib/ruvim/file_watcher.rb', line 37

def stop
  @stop = true
  @thread&.kill
  @thread&.join(0.5)
  @thread = nil
end