Class: Vizcore::DSL::FileWatcher
- Inherits:
-
Object
- Object
- Vizcore::DSL::FileWatcher
- Defined in:
- lib/vizcore/dsl/file_watcher.rb
Overview
Watches one scene file and invokes a callback when it changes.
Constant Summary collapse
- DEFAULT_POLL_INTERVAL =
Default polling interval in seconds when ‘listen` is unavailable.
0.25
Instance Method Summary collapse
-
#initialize(path:, poll_interval: DEFAULT_POLL_INTERVAL, listener_factory: nil) {|changed_path| ... } ⇒ FileWatcher
constructor
A new instance of FileWatcher.
- #running? ⇒ Boolean
- #start ⇒ Boolean
- #stop(timeout: 1.0) ⇒ void
Constructor Details
#initialize(path:, poll_interval: DEFAULT_POLL_INTERVAL, listener_factory: nil) {|changed_path| ... } ⇒ FileWatcher
Returns a new instance of FileWatcher.
16 17 18 19 20 21 22 23 24 |
# File 'lib/vizcore/dsl/file_watcher.rb', line 16 def initialize(path:, poll_interval: DEFAULT_POLL_INTERVAL, listener_factory: nil, &on_change) @path = Pathname.new(path.to_s). @poll_interval = Float(poll_interval) @listener_factory = listener_factory @on_change = on_change @running = false @listener = nil @thread = nil end |
Instance Method Details
#running? ⇒ Boolean
52 53 54 |
# File 'lib/vizcore/dsl/file_watcher.rb', line 52 def running? @running end |
#start ⇒ Boolean
27 28 29 30 31 32 |
# File 'lib/vizcore/dsl/file_watcher.rb', line 27 def start return if running? @running = true start_with_listener || start_with_polling end |
#stop(timeout: 1.0) ⇒ void
This method returns an undefined value.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vizcore/dsl/file_watcher.rb', line 36 def stop(timeout: 1.0) return unless running? @running = false @listener&.stop @listener = nil thread = @thread @thread = nil return unless thread return if thread == Thread.current thread.join(timeout) end |