Class: Listen::Adapters::Darwin
- Inherits:
-
Listen::Adapter
- Object
- Listen::Adapter
- Listen::Adapters::Darwin
- Defined in:
- lib/listen/adapters/darwin.rb
Overview
Adapter implementation for Mac OS X ‘FSEvents`.
Constant Summary collapse
- LAST_SEPARATOR_REGEX =
/\/$/
Constants inherited from Listen::Adapter
Listen::Adapter::DEFAULT_LATENCY, Listen::Adapter::POLLING_FALLBACK_MESSAGE
Instance Attribute Summary
Attributes inherited from Listen::Adapter
#directories, #latency, #paused
Class Method Summary collapse
-
.usable? ⇒ Boolean
Checks if the adapter is usable on the current OS.
Instance Method Summary collapse
-
#initialize(directories, options = {}, &callback) ⇒ Darwin
constructor
Initializes the Adapter.
-
#start(blocking = true) ⇒ Object
Starts the adapter.
-
#stop ⇒ Object
Stops the adapter.
Methods inherited from Listen::Adapter
select_and_initialize, #started?, usable_and_works?, #wait_for_callback, works?
Constructor Details
#initialize(directories, options = {}, &callback) ⇒ Darwin
Initializes the Adapter. See Listen::Adapter#initialize for more info.
12 13 14 15 |
# File 'lib/listen/adapters/darwin.rb', line 12 def initialize(directories, = {}, &callback) super @worker = init_worker end |
Class Method Details
.usable? ⇒ Boolean
Checks if the adapter is usable on the current OS.
54 55 56 57 58 59 60 61 |
# File 'lib/listen/adapters/darwin.rb', line 54 def self.usable? return false unless RbConfig::CONFIG['target_os'] =~ /darwin(1.+)?$/i require 'rb-fsevent' true rescue LoadError false end |
Instance Method Details
#start(blocking = true) ⇒ Object
Starts the adapter.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/listen/adapters/darwin.rb', line 21 def start(blocking = true) @mutex.synchronize do return if @stop == false super end @worker_thread = Thread.new { @worker.run } @poll_thread = Thread.new { poll_changed_dirs } # The FSEvent worker needs sometime to startup. Turnstiles can't # be used to wait for it as it runs in a loop. # TODO: Find a better way to block until the worker starts. sleep @latency @poll_thread.join if blocking end |
#stop ⇒ Object
Stops the adapter.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/listen/adapters/darwin.rb', line 39 def stop @mutex.synchronize do return if @stop == true super end @worker.stop Thread.kill(@worker_thread) if @worker_thread @poll_thread.join end |