Class: RuVim::FileWatcher::PollingWatcher
- Inherits:
-
Object
- Object
- RuVim::FileWatcher::PollingWatcher
- 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
-
#current_interval ⇒ Object
readonly
Returns the value of attribute current_interval.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #backend ⇒ Object
-
#initialize(path, &on_event) ⇒ PollingWatcher
constructor
A new instance of PollingWatcher.
- #start ⇒ Object
- #stop ⇒ Object
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_interval ⇒ Object (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
44 45 46 |
# File 'lib/ruvim/file_watcher.rb', line 44 def alive? @thread&.alive? || false end |
#backend ⇒ Object
20 |
# File 'lib/ruvim/file_watcher.rb', line 20 def backend = :polling |
#start ⇒ Object
32 33 34 35 |
# File 'lib/ruvim/file_watcher.rb', line 32 def start @stop = false @thread = Thread.new { poll_loop } end |
#stop ⇒ Object
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 |