Class: Klenod::Build::Watcher
- Inherits:
-
Object
- Object
- Klenod::Build::Watcher
- Defined in:
- lib/klenod/build/watcher.rb
Defined Under Namespace
Classes: PendingChanges
Instance Method Summary collapse
-
#initialize(source_dir:, context:, debounce_interval: 0.1) ⇒ Watcher
constructor
A new instance of Watcher.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(source_dir:, context:, debounce_interval: 0.1) ⇒ Watcher
Returns a new instance of Watcher.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/klenod/build/watcher.rb', line 56 def initialize(source_dir:, context:, debounce_interval: 0.1) @source_dir = source_dir @context = context @debounce_interval = debounce_interval @graph_version = 0 @pending_changes = PendingChanges.new @pending_mutex = Mutex.new @pending_condition = ConditionVariable.new @last_change_at = nil @stopping = false end |
Instance Method Details
#start ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/klenod/build/watcher.rb', line 68 def start @worker_thread = Thread.new { process_pending_updates } @listener = Listen.to(@source_dir) do |modified, added, removed| enqueue_update(modified + added, removed) end @listener.start end |
#stop ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/klenod/build/watcher.rb', line 77 def stop @listener&.stop @pending_mutex.synchronize do @stopping = true @pending_condition.broadcast end @worker_thread&.join end |