Sha256: 98e2922ea3f99026f1a375cc4742c8cb294848990e41759ddea163e2a87fa7d7

Contents?: true

Size: 1.52 KB

Versions: 210

Compression:

Stored size: 1.52 KB

Contents

module Listen
  module Adapters

    # The default delay between checking for changes.
    DEFAULT_POLLING_LATENCY = 1.0

    # Polling Adapter that works cross-platform and
    # has no dependencies. This is the adapter that
    # uses the most CPU processing power and has higher
    # file IO that the other implementations.
    #
    class Polling < Adapter

      # Initialize the Adapter. See {Listen::Adapter#initialize} for more info.
      #
      def initialize(directories, options = {}, &callback)
        @latency ||= DEFAULT_POLLING_LATENCY
        super
      end

      # Start the adapter.
      #
      # @param [Boolean] blocking whether or not to block the current thread after starting
      #
      def start(blocking = true)
        @mutex.synchronize do
          return if @stop == false
          super
        end

        @poll_thread = Thread.new { poll }
        @poll_thread.join if blocking
      end

      # Stop the adapter.
      #
      def stop
        @mutex.synchronize do
          return if @stop == true
          super
        end

        @poll_thread.join
      end

    private

      # Poll listener directory for file system changes.
      #
      def poll
        until @stop
          sleep(0.1) && next if @paused

          start = Time.now.to_f
          @callback.call(@directories.dup, :recursive => true)
          @turnstile.signal
          nap_time = @latency - (Time.now.to_f - start)
          sleep(nap_time) if nap_time > 0
        end
      rescue Interrupt
      end

    end

  end
end

Version data entries

210 entries across 120 versions & 5 rubygems

Version Path
classiccms-0.5.16 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.15 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.15 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.15 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.14 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.14 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.14 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.13 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.13 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.13 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.12 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.12 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.12 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.11 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.11 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.11 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.10 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.10 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.10 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.5.9 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/polling.rb