Class: Watchcat::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/watchcat/executor.rb

Instance Method Summary collapse

Constructor Details

#initialize(paths, recursive:, force_polling:, poll_interval:, filters:, debounce:, block:) ⇒ Executor

Returns a new instance of Executor.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/watchcat/executor.rb', line 5

def initialize(paths, recursive:, force_polling:, poll_interval:, filters:, debounce:, block:)
  @paths = paths
  @recursive = recursive
  @force_polling = force_polling
  @poll_interval = poll_interval
  @filters = filters || {}
  @debounce = debounce
  @debouncer = Debouncer.new if @debounce > 0
  @block = block
  @watcher = Watchcat::Watcher.new
  @watch_thread = nil
  @stop_requested = false
end

Instance Method Details

#startObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/watchcat/executor.rb', line 19

def start
  # Always start watching in a background thread to avoid blocking
  @watch_thread = Thread.new do
    Thread.current.name = "watchcat-watcher"
    start_watching
  end

  at_exit do
    stop
  end
end

#stopObject



31
32
33
34
35
36
37
# File 'lib/watchcat/executor.rb', line 31

def stop
  @stop_requested = true
  @watcher.close
  if @watch_thread && @watch_thread.alive?
    @watch_thread.join(1) # Wait up to 1 second for thread to finish
  end
end