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.7.5 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.5 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.5 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.3 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.3 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.3 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/polling.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sass-3.2.5/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.2 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.2 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.2 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.1 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.1 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/polling.rb
classiccms-0.7.1 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/polling.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sass-3.2.5/vendor/listen/lib/listen/adapters/polling.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sass-3.2.5/vendor/listen/lib/listen/adapters/polling.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sass-3.2.5/vendor/listen/lib/listen/adapters/polling.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sass-3.2.5/vendor/listen/lib/listen/adapters/polling.rb