Parent

Listen::Adapters::Darwin

Adapter implementation for Mac OS X `FSEvents`.

Public Class Methods

new(directories, options = {}, &callback) click to toggle source

Initializes the Adapter. See {Listen::Adapter#initialize} for more info.

# File lib/listen/adapters/darwin.rb, line 12
def initialize(directories, options = {}, &callback)
  super
  @worker = init_worker
end
usable?() click to toggle source

Checks if the adapter is usable on the current OS.

@return [Boolean] whether usable or not

# File lib/listen/adapters/darwin.rb, line 54
def self.usable?
  return false unless RbConfig::CONFIG['target_os'] =~ /darwin(1.+)?$/

  require 'rb-fsevent'
  true
rescue LoadError
  false
end

Public Instance Methods

start(blocking = true) click to toggle source

Starts the adapter.

@param [Boolean] blocking whether or not to block the current thread after starting

# 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() click to toggle source

Stops the adapter.

# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.